Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Refine X- Axis so that the distances are better recognizable

I have a problem. I have a dataframe df. I want to plot a scatterplot with the help of seaborn. But I want to change the x- axis. I would like the x-axis to be finer from 4.0 to 5.0. The distances should be smaller, e.g. 4.1, 4.2 or even finer.
How can I set so that the x-axis is displayed finer, so that I can see the values from 4.0 better?

I looked at seaborn, pylab – changing xticks from float to int , How to change the X axis range in seaborn in python?

d = {'review_scores_accuracy': [1.1, 2.0, 4.5, 5.0, 4.9, 4.8, 4.7], 
     'review_scores_rating': [1.1, 2.0, 4.6, 3.9, 4.2, 4.5, 4.2]}
df = pd.DataFrame(data=d)


fig, ax = plt.subplots(figsize=(20,10))
sns.scatterplot(data=df, x="review_scores_rating", y="review_scores_accuracy", ax = ax ) 
# ax.set_xlim(1,5)
# ax.set_xticks(1,2,3,4,4.1,4.2)
plt.show()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use matplotlib.ticker, as per here

import pandas as pd
import seaborn as sns
import matplotlib.ticker as ticker

d = {'review_scores_accuracy': [1.1, 2.0, 4.5, 5.0, 4.9, 4.8, 4.7], 
 'review_scores_rating': [1.1, 2.0, 4.6, 3.9, 4.2, 4.5, 4.2]}
df = pd.DataFrame(data=d)

fig, ax = plt.subplots(figsize=(20,10))
sns.scatterplot(data=df, x="review_scores_rating",y="review_scores_accuracy", ax=ax) 
ax.xaxis.set_major_locator(ticker.MultipleLocator(0.1))
plt.show()

enter image description here

Narrow your data range if you just want to plot between 4 and 5.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading