Reputation: 2075
My code below produces a graph where the labels on the x-axis are squished together and hard to read. How can I show just every other year instead of all years?
import seaborn as sns
import pandas as pd
years = list(range(1996,2017))
count = [2554.9425,2246.3233,1343.7322,973.9502,706.9818,702.0039,725.9288,
598.7818,579.0219,485.8281,474.9578,358.1385,311.4344,226.3332,
161.4288,132.7368,78.1659,39.8121,23.1321,0.2232,0.0015]
df = pd.DataFrame({'year':years, 'count':count})
dot_size = 0.7
ax = sns.pointplot(x="year",y="count", scale = dot_size, data=df)
ax.set(xlabel='Year', ylabel='Amount')
ax.set(ylim=(0, 3000))
Upvotes: 5
Views: 13262
Reputation: 11487
If you just want to show every other year instead of all years,you can use set_visible
method:
xticks=ax.xaxis.get_major_ticks()
for i in range(len(xticks)):
if i%2==1:
xticks[i].set_visible(False)
plt.show()
And you will get:
Actually,the spacing between labels is dynamic,I tried to run your code with plt.show()
,and resize the image window,and it looks better.
By the way,maybe
ax.set_xticklabels( years, rotation=45 )
is also a good way.
Hope this helps.
Upvotes: 9