简体   繁体   English

Matplotlib直方图,条之间没有线条

[英]Matplotlib Histogram with no lines between the bars

I want to plot a histogram with matplotlib that has lines delineating the histogram, but with no lines between the bars. 我想用matplotlib绘制直方图,该直线具有描绘直方图的线,但条之间没有线。 Something like this: 像这样:

在此处输入图片说明

How can I do that? 我怎样才能做到这一点?

Using plt.hist() , you need to create the histogram using the argument histtype="stepfilled" and set the edgecolor of the patches, which is by default set to None, in order to get the histogram the way you desire: 使用plt.hist() ,您需要使用参数histtype="stepfilled"创建直方图并设置色块的edgecolor (默认情况下设置为None),以便以所需的方式获取直方图:

import numpy as np
import matplotlib.pyplot as plt

data = np.random.randn(10000)

plt.hist(data, histtype="stepfilled", edgecolor='k', linewidth=1.2)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM