Issue
Here is my code:
import pandas as pd
import matplotlib.pyplot as plt
wine = pd.read_csv('red wine quality.csv')
wine = wine.dropna()
plt.figure()
wine.plot.scatter(x = 'pH', y = 'alcohol', c = 'quality', alpha = 0.4,\
cmap = plt.get_cmap('jet'), colorbar = True)
plt.savefig('scatter plot.png')
plt.tight_layout()
plt.show()
Here is the plot that I get:
I get a scatter plot with the y-axis labeled as 'alcohol' ranging from 9-15 and the color bar labeled as 'quality' ranging from 3-8. I thought I had designated in my code that the x-axis would show up labeled as 'pH', but I get nothing. I have tried adjusting my figsize down to [8, 8], setting dpi to 100, and labeling the axes, but nothing will make the x-axis show up. What am I doing wrong?
Here is an MCVE to play with:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.DataFrame(np.random.randn(50, 4), columns=['A', 'B', 'C', 'D'])
plt.figure()
df.plot.scatter(x = 'A', y = 'B', c = 'C', alpha = 0.4,\
cmap = plt.get_cmap('jet'), colorbar = True)
plt.tight_layout()
plt.show()
Solution
X axis label and minor tick labels not showing on Pandas scatter plot is a known and open issue with Pandas (see BUG: Scatterplot x-axis label disappears with colorscale when using matplotlib backend · Issue #36064).
This bug occurs with Jupyter notebooks displaying Pandas scatterplots that have a colormap while using Matplotlib as the plotting backend. The simplest workaround is passing sharex=False
to pandas.DataFrame.plot.scatter.
See Make pandas plot() show xlabel and xvalues
Answered By - marianoju
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.