1

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()

Jupyter plot

3
  • 2
    stackoverflow.com/q/10998621/1216776 Commented Apr 17, 2020 at 17:10
  • Thanks. Now I have to figure out how to change the Y-axis label.. Commented Apr 17, 2020 at 17:15
  • ax.set_ylabel('Time') Commented Apr 17, 2020 at 17:22

1 Answer 1

2

Use width = 0.1 for bar width:

ax.bar(df.index, df["country"], color="C0", width = 0.1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.