I want to scatter plot the first two columns of the following pandas.DataFrame, with the third column as color values.
>>>df = pd.DataFrame({'a': {'1128': -2, '1129': 0, '1146': -4, '1142': -3, '1154': -2,
'1130': -1, '1125': -1, '1126': -2, '1127': -5, '1135': -2},
'c': {'1128': 5300, '1129': 6500, '1146': 8900, '1142': 8900,
'1154': 9000, '1130': 5600, '1125': 9400, '1126': 6000, '1127': 7200,
'1135': 7700}, 'b': {'1128': -3, '1129': -10, '1146': -6, '1142': -3,
'1154': -7, '1130': -2, '1125': -7, '1126': -7, '1127': 0, '1135': -1}}
>>>df
a b c
did
1125 -1 -7 9400
1126 -2 -7 6000
1127 -5 0 7200
1128 -2 -3 5300
1129 0 -10 6500
1130 -1 -2 5600
1135 -2 -1 7700
1142 -3 -3 8900
1146 -4 -6 8900
1154 -2 -7 9000
If I try:
>>>df.plot('a', 'b', kind='scatter', color=df['c'], colormap='YlOrRd')
I get
And the X-axis disappears.
I tried ax.set_axis_on()
and ax.axis('on')
to no avail.
Marker Shape Just use the marker argument of the plot() function to custom the shape of the data points.
cmap: A map of colors to use in the plot.
scatter() Scatter plots are used to observe relationship between variables and uses dots to represent the relationship between them. The scatter() method in the matplotlib library is used to draw a scatter plot.
You can use sharex=False
:
df.plot('a', 'b', kind='scatter', color=df['c'], colormap='YlOrRd', sharex=False)
Idea from github.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With