【问题标题】:How to reproduce this plot's aestethics with matplotlib, seaborn or pandas [closed]如何使用 matplotlib、seaborn 和 pandas 重现这种情节美学 [关闭]
【发布时间】:2018-04-13 13:30:42
【问题描述】:

我喜欢以下地块的简洁设计 (source)。特别是偏移轴和刻度布局。

显然它们是用 R 制作的。对于我自己的绘图,我使用了 matplotlibpandas.DataFrame.plotseaborn 的组合。是否可以创建一个设置,使绘图默认布局为这样?

以前的尝试:seaborn.despine(offset=10) 偏移了轴,但它没有像所示那样格式化轴。如果轴为带有上述刻度的纯黑色,则以下最小示例将是完美的。网格线很有帮助,应尽可能保留:

seaborn.set_style("whitegrid")
seaborn.load_dataset("iris")["species"].value_counts().plot(kind="bar")
seaborn.despine(offset=10)

【问题讨论】:

  • 我没有投反对票,但这个问题不太适合 SO,因为您要求某人为您实施此问题,您能否展示您的尝试
  • 我希望有某种预定义的设置可供认识到问题的人推荐。
  • 我不这么认为,我不是绘图专家,但子情节肯定是微不足道的,我确定其他东西是可以使用的或可以在 matplotlib.org/examples 上找到但事实仍然你需要尝试展示你已经取得的成就,然后询问如何完成让你难过的最后几个步骤

标签: python r pandas matplotlib seaborn


【解决方案1】:

这能达到你想要的吗?

sns.set(style='ticks', rc={"axes.grid":True}) # to maintain grids with the ticks effect
X = np.random.randn(100)
ax = plt.subplot()
ax.hist(X, color='white', edgecolor='k')
sns.despine(ax=ax, offset=10, trim=True) # offset: the distance to the axis from the plot, trim: to trim off the edges like in R
plt.show()

更多内容在this answer

【讨论】:

  • 没错,谢谢。也可以通过设置matplotlib.pyplot.rcParams["axis.grid"] = True 来添加网格线,充分利用whitegridticks seaborn 样式。
  • 太棒了!你也可以使用sns.set(style='ticks', rc={"axes.grid":True})
  • 您无需复制另一个答案的内容,只需投票以将问题作为现有问题的副本结束。
  • @ImportanceOfBeingErnest 感谢您的评论。我认为我没有足够的特权投票关闭。至于这里的内容,我想这比链接的答案更具体地解决了 OP 的问题(轴和刻度布局)。
  • @akilat90 少于 3k 的代表用户可以标记为重复。
猜你喜欢
  • 1970-01-01
  • 2015-10-31
  • 2021-06-07
  • 1970-01-01
  • 2015-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多