我使用以下代码创建一个直方图,在一个图中显示频率和累积频率。 “正常”直方图以深蓝色显示,累积直方图以浅色显示。然而,两者非常接近且不易辨别。
如何为累积直方图设置不同的颜色或更浅的阴影?
sns.histplot(values, discrete=True, shrink=0.2)
sns.histplot(values, discrete=True, shrink=0.2, cumulative=True)
您可以修改代码以使用颜色参数为正常和累积直方图显式设置不同的颜色。这是一个将正常直方图设置为深蓝色并将累积直方图设置为浅蓝色的示例:
import seaborn as sns
# Your values
values = [...]
# Plot the normal histogram with a darker blue color
sns.histplot(values, discrete=True, shrink=0.2, color="darkblue")
# Plot the cumulative histogram with a lighter blue color
sns.histplot(values, discrete=True, shrink=0.2, cumulative=True, color="lightblue")
您可以将“darkblue”和“lightblue”替换为任何其他有效的颜色名称,例如“red”、“green”等,或者通过指定它们的 RGB 或 RGBA 值来使用自定义颜色,例如,color=(0.2, 0.4 , 0.6) 或 color=(0.2, 0.4, 0.6, 0.8) 分别。