I want to make a pandas.DataFrame.plot with colorbar. For reproducibility, here I use the code in
Here are the package versions of my Python environment.
- Python 3.8.12
- pandas 1.4.0
- matplotlib 3.5.1
Is there any suggestion of this issue? Thanks!
Additional information: I use macOS Big Sur version 11.6 on MacBook Pro M1.
CodePudding user response:
Can you try:
fig, ax = plt.subplots()
cm = plt.cm.get_cmap('Greys')
sc = ax.scatter(df['x'], df['y'], s=500, c=df['score'],
vmin=df['score'].min(), vmax=df['score'].max(), cmap=cm)
cb = fig.colorbar(sc)
t = cb.set_label('score', rotation=-90)
ax.set_xlim( [-0.5,9.5] )
ax.set_ylim( [-0.5,9.5] )
ax.set_xlabel('x')
ax.set_ylabel('y')
plt.tight_layout()
plt.show()
Output: