I have a list like list1 = ['A1', 'A2', 'A1', 'A3']. I want to use this one for the x-axis subplot-label, but every time I plot this using matplotlib, the x - values are shortend like "A1 A2 A3" and A1 gets two y values in the plot figure.
Is there a way to stop the automated "compressing" of the x-axis label?
So instead of "A1 A2 A3" I want a x-label"A1 A2 A1 A3" in the way the list actually is.
Thanks in advance!
CodePudding user response:
If you send your code, we can help you better but I send two example, maybe helps you.
First Example: For this purpose, you need to define key
for each label.
import matplotlib.pyplot as plt
f, ax = plt.subplots()
x = ['A1', 'A2', 'A1', 'A3']
l = [1, 2, 3, 4]
y = [2, 3, 4,5]
ax.plot(l,y)
ax.set_xticks(l)
ax.set_xticklabels(x)
plt.show()
Output:
Second Example:
import matplotlib.pyplot as plt
f, ax = plt.subplots()
x = ['A1', 'A2', 'A1', 'A3']
l = [1, 2, 1, 4]
y = [2, 3, 4,5]
ax.plot(l,y)
ax.set_xticks(l)
ax.set_xticklabels(x)
plt.show()
Output: