季节性直方图使列变白

问题描述 投票:1回答:1

在什么情况下,Seaborn使直方图列变为白色?我在Jupyter笔记本中使用了Seaborn:

import matplotlib.pyplot as plt
import seaborn as sns
sns.set()

然后我使用此功能绘制直方图:

def plot_hist(data, xlabel, bins=None):

  if not bins:
      bins = int(np.sqrt(len(data)))

  _= plt.xlabel(xlabel)
  _= plt.hist(data, bins=bins)

因此,在某些情况下,我的直方图包含所有蓝色列或一些蓝色和一些白色或仅白色列。请参阅所附图片。

如何使Seaborn总是绘制蓝色列?

blue columns

blue and white

white

python python-3.x matplotlib jupyter-notebook seaborn
1个回答
1
投票

[我相信问题在于直方图的edgecolorwhite,并且随着增加分档数或减小条形的宽度,edgecolor开始覆盖facecolor。您应该可以通过使用更高的dpi来解决它,

# globally
from matplotlib import rcParams
rcParams['figure.dpi'] = 300
# or for only this figure
fig = plt.figure(dpi=300)

更薄的linewidth

# globally
from matplotlib import rcParams
rcParams['patch.linewidth'] = 0.5
# or for only this plot
_= plt.hist(data, bins=bins, linewidth=0.5)

或完全删除轮廓,

_= plt.hist(data, bins=bins, edgecolor=None)

请注意,全局方法可能需要在sns.set()之后,因为这可能会覆盖它们。

© www.soinside.com 2019 - 2024. All rights reserved.