Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scatter plot with colormap makes X-axis disappear

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

Plot with no X axis

And the X-axis disappears.

I tried ax.set_axis_on() and ax.axis('on') to no avail.

like image 638
Eran Avatar asked Jan 10 '18 12:01

Eran


People also ask

How do you change a marker shape in a scatter plot in Python?

Marker Shape Just use the marker argument of the plot() function to custom the shape of the data points.

What is CMAP PLT scatter?

cmap: A map of colors to use in the plot.

What does PLT scatter do?

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.


Video Answer


1 Answers

You can use sharex=False:

df.plot('a', 'b', kind='scatter', color=df['c'], colormap='YlOrRd', sharex=False)

Idea from github.

graph

like image 180
jezrael Avatar answered Oct 23 '22 18:10

jezrael