- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用 Python 中的 Matplotlib 和 matplotlib.bar()
函数绘制直方图。这给了我看起来像这样的情节:
我正在尝试生成一个直方图,该直方图仅绘制每个条形的上限以及不直接与另一个条形边界共享空间的边,更像这样:(我使用 gimp 编辑了它)
如何使用 Python 实现此目的?使用 matplotlib
的答案更可取,因为这是我最有经验的,但我对任何使用 Python 的作品持开放态度。
关于它的值(value),这里是相关代码:
import numpy as np
import matplotlib.pyplot as pp
bin_edges, bin_values = np.loadtxt("datafile.dat",unpack=True)
bin_edges = np.append(bin_edges,500.0)
bin_widths = []
for j in range(len(bin_values)):
bin_widths.append(bin_edges[j+1] - bin_edges[j])
pp.bar(bin_edges[:-1],bin_values,width=bin_widths,color="none",edgecolor='black',lw=2)
pp.savefig("name.pdf")
最佳答案
我想最简单的方法是使用 step 函数而不是 bar: http://matplotlib.org/examples/pylab_examples/step_demo.html
例子:
import numpy as np
import matplotlib.pyplot as pp
# Simulate data
bin_edges = np.arange(100)
bin_values = np.exp(-np.arange(100)/5.0)
# Prepare figure output
pp.figure(figsize=(7,7),edgecolor='k',facecolor='w')
pp.step(bin_edges,bin_values, where='post',color='k',lw=2)
pp.tight_layout(pad=0.25)
pp.show()
如果给定的 bin_edges 代表左边缘,请使用 where='post';如果他们在右边,使用 where='pre'。我看到的唯一问题是,如果您使用 post (pre),该步骤并没有真正正确地绘制最后一个(第一个)bin。但是您可以在数据之前/之后添加另一个 0 bin,以使其正确绘制所有内容。
示例 2 - 如果您想对一些数据进行分箱并绘制直方图,您可以这样做:
# Simulate data
data = np.random.rand(1000)
# Prepare histogram
nBins = 100
rng = [0,1]
n,bins = np.histogram(data,nBins,rng)
x = bins[:-1] + 0.5*np.diff(bins)
# Prepare figure output
pp.figure(figsize=(7,7),edgecolor='k',facecolor='w')
pp.step(x,n,where='mid',color='k',lw=2)
pp.show()
关于Python Matplotlib : plotting histogram with overlapping boundaries removed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37998017/
在 HTML 表单中发布用于创建多部分边界的有效字符是什么? 最佳答案 根据 RFC 2046 ,第 5.1.1 节: boundary := 0*69 bcharsnospace bchars
大家好,我卡颂。 本文会讲解React中Error Boundaries的完整实现逻辑。 一张图概括: 这里简单讲解下React工作流程,后文有用。分为三步: 触发更新
我正在尝试编写我的第一个 Elasticsearch 分析插件,我从 github 上找到了一个可扩展标准分析器插件项目:elasticsearch-analysis-standardext ,在项目
我正在开发一款游戏,其中你是一个发射子弹的简单圆圈及其多人游戏等等。好吧,我试图让边界有点像你必须经历的迷宫类型的东西,我尝试过这样的碰撞检测: public void checkCollisions
我想设置一个模式,该模式将找到一个受第一次出现的“边界”限制的捕获组。但是现在使用最后一个边界。 例如: String text = "this should match from A to the
我想根据旋转矩阵计算欧拉角,以便找出与该旋转关联的方向。为此,我正在使用 MATLAB 和函数 rotm2eul,它首先提供关于 x 轴的旋转,然后是关于 y 轴的旋转,最后是关于 z 轴的旋转。 我
这个问题已经有答案了: No out of bounds error (7 个回答) 已关闭 7 年前。 在下面的代码中,我已将值分配给超出数组边界的数组元素,在 CLI 的 Linux 环境中,代码
我尝试使用 Python 请求模块将一些数据和文件发送到我的 django rest 应用程序,但出现以下错误。 raise MultiPartParserError('Invalid bou
我正在尝试为我玩的游戏开发一个在线 map 编辑程序。 map 的数据有点大。如果我发送每个方格的数据,中等大小 map 的数据接近 1 mb。 我认为我可以做的是在 map 上找到边界并以此为基础创
“Android 设计”网站推荐可 ScrollView 的“边界反馈”。 http://developer.android.com/design/style/touch-feedback.html
引用此 post 中给出的最佳答案,我注意到当 rnd=sum_of_weight 时,它在边界情况下失败。解决方法是在 [0,sum_of_weight) 中生成随机数,但是我想知道为什么代码对于这
在多部分(即 Content-Type=multipart/form-data)形式中,HTTP 服务器应该接受的边界字符串的长度是否有上限? 据我所知,相关的 RFC 说 70 个字符: RFC26
我有一串任意字符,其中一些是数字。我想将字符串分成由数字和非数字组成的字段。例如,如果我的字符串的值为 'abc34d-f9',我想得到一个数组 ['abc','34','d-f','9'] 我快到了
我正在尝试创建有关 Scooter 系统的用例图。我已经创建了图表,你可以在这里找到它: Use Case Diagram : 我收到了一些关于这张图的评论: 系统(或滑板车供应商)不是 Actor
我正在尝试从桌面上传图像,但找不到多部分边界的错误。如何设置上传图片的边界?第一次上传图片,请指教。 用户上传图片时的html事件监听 document.getElementById('image-f
我在发送带有文本附件的电子邮件时遇到问题(没有附件,一切都很好)。我正在使用 actionmailer 3.2.11 并尝试通过 Amazon SES 发送电子邮件。在我看来,亚马逊 snmp 服务器
来自 Akka 文档,Pipelining and Parallelism Akka Streams processing stages (be it simple operators on Flow
有一个 DAL 库公开了十几个存储库。每个实体一个存储库。有 PersonRepository 和 PhotoRepository。 当我向存储库添加新方法并且方法处理实体时,很明显我必须将它放在哪里
引用:perl string catenation and substitution in a single line? 给定输入: home/////test/tmp/ 以及所需的转换为: /hom
我有一个看起来像这样的大文件: V1 SNP1 SNP2 SNP3 SNP4 SNP5 SNP6 SNP7 SNP8 SNP9 GROUP1 1 NA 2 1 1
我是一名优秀的程序员,十分优秀!