I am somewhat new with python plots using matplotlib, so please excuse me.
I want to plot a group bar plot, and I want to have two of those bars on secondary axis since those two have values at much lower range compared to other bars in the group. Is it possible? I could not find any solution online or in matplotlib documentation.
I do know that we can do secondary axis plot e.g.
df.plot(kind="bar",figsize=(30, 10),secondary_y= 'columnWithLowValueRange', rot = 0)
However, even for one column this option somehow messes up my formatting. e.g the legend box is overlapped with secondary axis legend name and the ylabel for primary axis goes missing etc.
This is what my current plot looks like.
As you can see some of the vals are barely visible. So, I would like to plot val6 and val7 on secondary plot.
My current code is like this:
df = df1.loc[tag_df['names'] == max_val]
del df['names']
df.set_index('names', inplace=True)
df.plot(kind="bar",figsize=(30, 10))
plt.title("myPlot", fontsize = 19)
xlabel= plt.xlabel("my x axis", fontsize = 17, color = "dimgray")
plt.ylabel("my y axis", fontsize = 16.5, color = "dimgray")
plt.legend(loc = 'upper right', fontsize = 12)
plt.xticks(fontsize=14, rotation=360)
plt.yticks(fontsize=14)
plt.grid(linestyle ='-', axis = 'y')
plt.savefig("myfig.png")
plt.clf()
df has those val1-val6 columns. The reference plot is excel plot but, my python plot is also very similar.
Any help here is highly appreciated. I have already searched stackoverflow for this, so hopefully it will not be marked as duplicate.
Thanks
question from:
https://stackoverflow.com/questions/66057707/how-to-get-two-columns-on-secondary-axis-using-matplotlib 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…