Andrew Smith Andrew Smith - 10 days ago 5
Python Question

Adding text labels to a simple matplotlib chart

I'm trying to add text labels to a simple matplotlib chart and nothing I've tried has worked.

plt.plot(SpringLikes)
plt.xlabel("Event")
labels=("SpringThemes")
plt.ylabel("No. of Likes")
plt.show()


enter image description here

It's a simple plot of the # of FB Likes per Event. I want the tick marks on the X axis to be the names of those events, which have been saved from a Pandas Dataframe into the variable "SpringThemes"

Any idea why this is not displaying the Themes as the tickmark labels on the x axis?

Answer

Let's say for example you have a list for your x axis:

x = [1,2,3,4]

You can add ticks on it like this:

plt.xticks([Game 1, Game 2, Game 3,Game 4])

Thus changing the x axis label.

Comments