【问题标题】:removing scientific notation from axis tick labels in matplotlib (log scale)从 matplotlib 中的轴刻度标签中删除科学记数法(对数刻度)
【发布时间】:2021-07-01 19:50:01
【问题描述】:

我有下图,正如您所见,由于 3x10^3、4x10^3 和 5x10^3 的科学记数法,y 轴刻度标签在 3000、4000 和 5000 处有重叠,尽管我是强制的我自己的刻度标签,我的问题是如何删除这些标签?

我尝试了plt.ticklabel_format(style='plain'),但这给出了错误:“AttributeError: This method only works with the ScalarFormatter.”

# multivariate plot of price by cut and color, for approx. 1 carat diamonds
myticks = [2300, 2600, 3000, 3300, 3600, 4000, 4300, 4600, 5000]
ytick_names = ['{}'.format(tick) for tick in myticks]

diamonds_sub = diamonds[diamonds['carat'].between(0.5, 1.5)]
plt.figure(figsize=(12,5))
sb.pointplot(data=diamonds_sub, x='color', y='price', hue='cut')
plt.yscale('log')
plt.yticks(myticks, ytick_names);

【问题讨论】:

    标签: python matplotlib data-analysis


    【解决方案1】:

    通过添加plt.gca().set_yticklabels([], minor=True)解决了这个问题

    【讨论】:

      猜你喜欢
      • 2017-10-07
      • 2020-07-29
      • 1970-01-01
      • 2014-03-22
      • 2012-03-14
      • 2021-06-14
      • 1970-01-01
      • 2011-03-28
      相关资源
      最近更新 更多