1

I have the following code. I am trying to plot a line plot.

However, it is plotting too many x-values on the x-axis.

I would like to plot fewer x-axis values (plot one value every few values) so that the x-axis scale is readable.

I would be so grateful for a helping hand!

plt.figure(figsize=(70,70))
ax = sns.lineplot(data=correcteddf,x=listedvariables[i],y="distance",errorbar ='se',err_style='bars',linewidth=4)
ax.set_xlabel('nap_duration_mins',labelpad = 40,fontsize=70,weight='bold')
ax.set_ylabel("Wayfinding Distance (z-score)",labelpad = 40,fontsize=70,weight='bold')
correcteddf[['nap_duration_mins']] = correcteddf[['nap_duration_mins']].astype(float)
ylabels = ['{:,.2f}'.format(x) for x in ax.get_yticks()]
xlabels = ['{:,.2f}'.format(x) for x in ax.get_xticks()]
ax.set_yticklabels(ylabels,weight='bold',fontsize=60)
ax.set_xticklabels(xlabels,weight='bold',fontsize=60,rotation = 30)
plt.xticks(rotation = 30,weight='bold',fontsize=60)
title = ('nap_duration_mins' + ' ' + 'plot')
ax.set_title(title,fontsize=70,pad=40,weight='bold') 
dir_name = "/Users/macbook/Desktop/"
plt.rcParams["savefig.directory"] = os.chdir(os.path.dirname(dir_name))
plt.savefig('nap_duration_mins+' '+'scatterplot')
plt.show()

enter image description here

1
  • your question says it's about sns.lineplot but the code seems to imply you are using matplotlib.pyplot. It's the latter one, right? Commented Nov 29, 2022 at 12:26

1 Answer 1

1

Here you can see the relevant documentation. Change the line

plt.xticks(rotation = 30,weight='bold',fontsize=60)

to

plt.xticks(ticks = list(range(0,70_000,10_000)),rotation = 30,weight='bold',fontsize=60)

and you will have ticks at only every 10 thousand steps. You can change the list to suit your needs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.