【问题标题】:Grid lines are not showing in my plot in Jupter notebook我在 Jupyter 笔记本中的绘图中没有显示网格线
【发布时间】:2019-03-31 13:43:19
【问题描述】:

我正在尝试使用 seaborn 绘制分布图,但没有得到图中的网格线。

import seaborn as sns
%matplotlib inline

sns.distplot(df_0['temp'], bins=20)

Below is the image for reference

  [1]: https://i.stack.imgur.com/q7z4W.png

【问题讨论】:

  • 默认没有网格线。您是否遵循文档中的任何 seaborn 示例?你有没有写任何代码行来打开网格?

标签: python data-visualization seaborn data-science


【解决方案1】:

sns.distplot(df_0['temp'], bins=20).grid()

seaborn.distplot 返回底层的 Matplotlib 轴对象,因此您可以进一步操作它。例如:

ax = sns.distplot(df_0['temp'], bins=20)
ax.grid()
ax.axvline(10)

此外,如 seaborn 文档中所示,您可以通过设置 seaborn 样式获得网格线以及其他美学:

seaborn.set_style('whitegrid')
sns.distplot(df_0['temp'], bins=20)

【讨论】:

  • 直方图垂直线也没有显示在溶解中的图表中。我也想得到垂直的白线来分隔条
  • hist_kws={'edgecolor': 'white'} 添加到您的 displot 调用中。如果我的回答解决了问题,请点赞并标记为正确,谢谢。
【解决方案2】:

默认情况下没有网格线。 在我的 distplot 调用中添加了 hist_kws={'edgecolor': 'white'}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-22
    • 2019-03-17
    • 1970-01-01
    • 2020-10-27
    • 2022-07-21
    • 2018-04-17
    • 1970-01-01
    • 2018-02-26
    相关资源
    最近更新 更多