1

Im am writing a Python Code. My dataset is composed of three columns, the firs two are the coordinates, and the third is a heat estimation

                   X              Y      heat
0      497935.000000  179719.000000  0.048428
1      497935.000000  179719.000000  0.029399
2      497935.000000  179719.000000  0.066734
3      497935.000000  179719.000000  0.065524
4      497935.000000  179719.000000  0.062458
5      497935.000000  179719.000000  0.032225
6      497935.000000  179719.000000  0.028557
7      497463.000000  179526.000000  0.000388
8      497899.000000  179305.000000  0.000733
9      497805.000000  179364.000000  0.000158
10     498264.000000  180349.000000  0.000036
11     498020.000000  179602.000000  0.003149
...              ...            ...       ...

I would like to plot the data in the XY plane, assigning a colour to each point with reflects its heat value. For the moment I tried with the command

plt.scatter(df.X, df.Y)

enter image description here

but where every dot has a colour with depends on its heat, in Python. Thanks in Advance

Duccio Piovani
  • 1,410
  • 2
  • 15
  • 27

1 Answers1

3

From the documentation:

The keyword c may be given as the name of a column to provide colors for each point:

In [64]: df.plot.scatter(x='a', y='b', c='c', s=50);

So what you need to do is to simply specify that the heat column contains the information about each point's color:

df.plot.scatter(x=data.X, y=data.Y, c=data.heat)

If you want to apply a custom color map, there is also the cmap parameter, allowing you to specify a different color map

You can also read more about in in the docs for the scatter() method.

plamut
  • 3,085
  • 10
  • 29
  • 40