python - Python - can you plot a histogram with a contour?
问题描述
I want to plot a histogram with a contour like this
I found this picture in here, but after following the same procedure there I don't get the contour.
I saw this question in stack overflow but it draws an edge over each bar, and I want only the outer contour.
How can I draw this outer contour? (I'm running python 3)
解决方案
该图可能是使用不同的(即较旧的)matplotlib 版本生成的。这也可以从 的使用中看出,normed
在较新的版本中已弃用。
在这里,您将明确地将边缘颜色设置为黑色。
ec="k"
, 或更长, edgecolor="black"
.
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-white')
x1 = np.random.normal(0, 0.8, 1000)
x2 = np.random.normal(-2, 1, 1000)
x3 = np.random.normal(3, 2, 1000)
kwargs = dict(histtype='stepfilled', alpha=0.3, density=True, bins=40, ec="k")
plt.hist(x1, **kwargs)
plt.hist(x2, **kwargs)
plt.hist(x3, **kwargs);
plt.show()
推荐阅读
- assembly - 演示处理器环 - 运行环 0 指令的汇编代码
- excel - 有没有办法根据相邻单元格值将单元格值添加到运行总计中?
- javascript - 在嵌入 iframe 的 Google SpreadSheet 中,如何在 iframe 中打开超链接而不是在新选项卡中打开?
- html - 未折叠时自定义/格式化导航栏(导航栏折叠折叠)。MVC
- mongodb - 在 insert_one() 之后使用 $lookup
- python - 为什么在 DJANGO 中扩展 CreateView CBV 时表单返回“方法不允许”
- javascript - 在选中单选按钮之前,必须禁用输入字段
- mysql - 从 sql 中的事件日志表获取步骤持续时间到累积快照事实的有效查询
- javascript - 如果 querySelector 不返回 null,则速记获取 textContent
- typescript - 如何在不使用 TypeORM 中的嵌入实体的情况下将类似的列添加到所有实体?