0

I'm trying to make a point plot of a data frame but all the values on the x axis are shown and is impossible to read. How can I scale the x axis in order for it to just show ticks instead of all the values? here's my code:

plt.figure(figsize=(12,5))
sns.pointplot(data=who_air_gdp, x='gdp_md_est', y='PM10 (μg/m3)', hue='World Bank ranking of income 2019')
plt.title('PM10 per GDP')
sns.despine()
plt.tight_layout()
plt.xlabel('GDP')
plt.ylabel('PM10 (μg/m3)')
plt.show()

and here is the resulting plot: enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • 2
    It should happen automatically, so I assume that your `x` is not numeric and is being plotted as categoric. Did you check the `dtype` of `gdp_md_est`. I suspect there is something wrong going on when reading the data and you end up with an `object` column. – Droid May 17 '23 at 14:15
  • 2
    Actually, `pointplot` is categorical, so all values are on the x-axis. In this case, you should probably use `sns.lineplot`. Additionally, the question is missing a complete [mre], which includes reproducible data. – Trenton McKinney May 17 '23 at 14:22
  • 1
    You're right. However, I think OP initial intention was not to use a categorical plot if I understand correctly. – Droid May 17 '23 at 14:24
  • Thank you, both for your comments. I, indeed, was not planning on using a categorical plot. My mistake. A line plot gives me the result a was looking for, although it is not exactly a continuous variable as time but actual GDP for each country – jspenaranda May 17 '23 at 14:36
  • 1
    In that case, it probably should be a categorical plot. But I suggest using a horizontal bar plot, since there a quite a few categories, make the plot longer. `g = sns.catplot(data=df, x='gdp_md_est', y='PM10 (μg/m3)', kind='bar', orient='h', col='World Bank ranking of income 2019', col_wrap=2, height=7, aspect=1)` – Trenton McKinney May 17 '23 at 15:05

0 Answers0