Reputation: 2288
I'm trying to make some manipulations with tick labels in matplotlib. But it seems that code does not do what I want, and I have no idea why? There is no labels.
In[1]: import matplotlib.pyplot as plt
import numpy as np
In[2]: x = np.arange(0,10)
In[3]: plt.plot(x,x)
locs, labs = plt.xticks()
plt.xticks(locs[1:], labs[1:])
plt.show()
Any help please! What I want is to delete first label on x axis:
I'm using:
python 3.5.2
matplotlib 1.5.3
win 10
Upvotes: 3
Views: 29693
Reputation: 21663
This is a direct answer to your question, rather than a remedy to your predicament.
>>> locs, labs = plt.xticks()
>>> locs
array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])
>>> labs
<a list of 10 Text xticklabel objects>
Notice that when you make a get call to xticks it yields a one-dimensional array of locations for tick marks and a list of objects. However, when you make a put call to xticks it expects an array-like collection of locations and an array-like collection of strings. For some reason, xticks seems to have failed to croak upon being given that list of objects.
Upvotes: 2
Reputation: 15433
fig, ax = plt.subplots()
ax.plot(x, x)
ticks = ax.get_xticks()
ax.set_xticks(ticks[1:])
plt.show()
Upvotes: 6
Reputation: 14236
Try this:
locs, labs = plt.xticks()
plt.xticks(locs[1:])
plt.show()
Upvotes: 4