Reputation: 61
I'm having trouble making my graphic more attractive for a publication, I'm not a programmer, but I found an easy way to make the graphic below. The bars are too thick and I'm not able to put the label on the left side. Also, the legend of the bars are superimposed, could someone help me?
from matplotlib.ticker import PercentFormatter
df = pd.DataFrame({'country': [40.91, 23.68, 21.53, 55.77, 47.50,
62.59]})
df.index = ['Linha de Produção – 1', 'Linha de Produção – 2', 'Linha de Produção – 3', 'Linha de Produção – 4', 'Linha de Produção – 5', 'Linha de Produção – 6']
df = df.sort_values(by='country',ascending=False) df["cumpercentage"] =
df["country"].cumsum()/df["country"].sum()*100
fig, ax = plt.subplots()
ax.bar(df.index, df["country"], color="C0")
ax2 = ax.twinx()
ax2.plot(df.index, df["cumpercentage"], color="C1", marker="D", ms=7)
ax2.yaxis.set_major_formatter(PercentFormatter())
plt.ylabel('NOME DO EIXO Y')
plt.grid(True)
ax.tick_params(axis="y", colors="C0")
ax2.tick_params(axis="y", colors="C1")
plt.show()
Upvotes: 1
Views: 35
Reputation: 186
Use width = 0.1 for bar width:
ax.bar(df.index, df["country"], color="C0", width = 0.1)
Upvotes: 2