Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plot with custom text for x axis points

People also ask

How do you change the X-axis labels in python?

To set labels on the x-axis and y-axis, use the plt. xlabel() and plt. ylabel() methods.

How do you label X-axis in PLT?

With Pyplot, you can use the xlabel() and ylabel() functions to set a label for the x- and y-axis.


You can manually set xticks (and yticks) using pyplot.xticks:

import matplotlib.pyplot as plt
import numpy as np

x = np.array([0,1,2,3])
y = np.array([20,21,22,23])
my_xticks = ['John','Arnold','Mavis','Matt']
plt.xticks(x, my_xticks)
plt.plot(x, y)
plt.show()


This worked for me. Each month on X axis

str_month_list = ['January','February','March','April','May','June','July','August','September','October','November','December']
ax.set_xticks(range(0,12))
ax.set_xticklabels(str_month_list)