Home > Software engineering >  Problem with replacing tick marks on the x axis using bar plot
Problem with replacing tick marks on the x axis using bar plot

Time:08-02

I'm trying to graph this bar graph using plt.bar . This is my code

x_axis = np.arange(0,len(drug_name))
tick_locations = []
for x in x_axis:
    tick_locations.append(x)

plt.bar(x_axis, total_tp_per_drug, facecolor = "orangered", alpha = 0.75, align = "center") 
plt.xticks(tick_locations, drug_name)
plt.show()

Everything is perfect except for when I'm trying to replace the tick marks on the x axis with the drug name labels it's not doing it. Can someone help me?

This is what's in drug_name

enter image description here

and this is the output

enter image description here

CodePudding user response:

The drug names are there, in your bar chart, but the default orientation is horizontal, so they're overlapping and unreadable. Try rotating the labels:

plt.xticks(tick_locations, drug_name, rotation=90)

(rotation=45 would put them at an angle and might make them more readable)

  • Related