python - Matplotlib.hist - 使用阶梯直方图平滑点之间的线
问题描述
我正在尝试平滑点之间的线。增加垃圾箱的数量是一种方法,但在我的真实数据上仍然无法解决问题。
def plotstep_test(x, y, z):
plt.figure(figsize=[10, 6])
plt.hist([x, y, z], color=['red','black', 'green'], histtype='step', bins=20)
plt.gca().spines['right'].set_color('none')
plt.gca().spines['top'].set_color('none')
plt.title('', fontsize=14)
plt.xlabel('', fontsize=14, labelpad=5)
plt.ylabel('', fontsize=14, labelpad=5)
plt.xticks(np.arange(0, 1.1, step=0.1), fontsize=12)
plt.yticks(fontsize=12)
plt.tick_params(axis='both', which='both', left=True, bottom=True,labelbottom=True)
plt.show()
使用随机数:
plotstep_test(np.random.uniform(size=10), np.random.uniform(size=5), np.random.uniform(size=50))
解决方案
It sounds like you might prefer a kernel density estimation to a histogram. Then you'll have complete control over the smoothness of the estimate.
Try seaborn.distplot()
:
data = np.random.normal(size=100)
import seaborn as sns
sns.distplot(data)
This gives you:
If you like the look of the line, you can get the rest of your stuff working no problem I'm sure.
In general, seaborn
makes really nice statistical plots. Check out the gallery.
推荐阅读
- javascript - usePreviousDistinct 有 useEffect 和没有 useEffect 之间的区别
- saxon - xsl:accumulator 中的副作用
- selenium - Robotframework如何做一个TextField值应该是IN a Loop?
- docker - Windows 容器的 dockerfile 中的问题设置 [Net.ServicePointManager]::SecurityProtocol
- mysql - MySQL 错误 1215 无法添加外键约束
- python - 如何在pytube3中使用进度条
- java - 日志文件中没有打印日志,但它正在打印在 cosole [log4j]
- python - Python 3 已安装,但 python -V 返回 python 2
- javascript - 无法使用 AWS Lambda 服务从 AWS cognito 获取用户信息
- go - 致命错误:所有 goroutine 都处于休眠状态 - 死锁!goroutine 1 [semacquire]: