the colour for each bar is different in the solution. But it is all blue in my work, how to fix it?
I’m not answering based on this specific question but generally, but it should be easy for you to learn something and tweak from my answer.
You can highlight certain important bars in a barplot by providing a list of colors in the color argument,
df.plot.bar(color=['red','red']+['blue']*8) in this case first 2 of 10 bars are highlighted red.
If you have more than 10 items to plot and the 10 default colors start to cycle and you don’t
from cycler import cycler N = 19 # number of colors plt.rcParams["axes.prop_cycle"] = cycler('color', plt.cm.tab20(np.linspace(0,1,N)) )
The default color cycle is called tab10 under “Qualitative Colormaps” from https://matplotlib.org/users/colormaps.html
This is a permanent change within 1 jupyter session as plt.rcParams is a dictionary (
plt.rcParams.keys() to see what you can control) that matplotlib refers to for all plotting. You can overwrite the default back later.
sns.color_palette it can make use of context manager coding style for you to temporarily change these things https://seaborn.pydata.org/generated/seaborn.color_palette.html
You can substitute the
plt.cm.tab20 i pasted above with anything on that colormaps page. You can create your own color map and control whether it is discrete or continuous, and edit vmax,vmin to 1,-1 (especially useful when doing correlation heatmaps) to make the whitest middle part of a diverging colorbar (suitable for correlation plots) occur at correlation coefficient = 0 and to let the correlation data use the entire range of colors possible in that diverging colorbar