更改 matplotlib 中图的线条样式
我正在绘制一些数据(两条线),并且我想更改线条之间差异具有统计显着性的部分的线条样式。因此,在下图中(现在链接 b/c 反垃圾邮件政策不允许我发布图像),我希望线条看起来有所不同(即可能是虚线),直到它们开始在 35 左右收敛x 轴。
有没有办法轻松做到这一点?我的 x 轴值差异很大,我只是不清楚如何更改某些 x 轴位置的线条样式。
I'm graphing some data (two lines) and I'd like to change the line style for the portions of the lines where the difference between them is statistically significant. So, in the below image (now a link b/c anti-spam policies don't allow me to post an image) I'd like the lines to look different (i.e. dashed perhaps) up until they start converging at about 35 on the x axis.
Is there a way to do this easily? I have the values for the x axis where the differences are significant, I'm just not clear how to change line styles at certain x-axis locations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:我已经打开并离开了,所以我没有注意到@Ricardo的答案。因为 matplotlib 无论如何都会将东西转换为 numpy 数组,所以有更有效的方法来做到这一点。
举个例子:
只需绘制两条不同的线,一条具有虚线样式,另一条具有实线样式。
例如
对于循环的情况,请使用屏蔽数组:
Edit: I'd had this open and left, so I didn't notice @Ricardo's answer. Because matplotlib will convert things to numpy arrays regardless, there are more efficient ways to do it.
As an example:
Just plot two different lines, one with a dashed linestyle and another with a solid linestyle.
E.g.
For the case where they're cyclic, use masked arrays:
假设您的数据位于 NumPy 数组
dataset1
和dataset2
上,并且您已将threshold
定义为您的重要性Let's say that your data is on NumPy arrays
dataset1
anddataset2
and you've definedthreshold
as your significance