使用比数据点更少的标记进行绘图(或者绘制 CDF 的更好方法?)[matplotlib,或一般绘图帮助]

发布于 2024-08-17 14:12:18 字数 724 浏览 7 评论 0原文

我正在绘制带有大量数据点的累积分布函数。我在同一个图上绘制了几条线,这些线用标记进行标识,因为它将以黑白打印。我想要的是在 x 维度上均匀分布的标记。我得到的是每个数据点一个标记(并且考虑到点的数量,它们都重叠)

我不确定这是我对如何绘制好图的理解,还是只是缺乏对 matplotlib 的理解。我找不到“标记频率”设置。

对于一行来说,一个简单的解决方案是从该行中取出第 N 个值,并将其用作带有 linestyle='' 的单独行,但我希望标记垂直对齐,并且不同的 x 数组具有不同的值长度。

# in reality, many thousands of values
x_example = [ 567, 460, 66, 1034, 275, 26, 628, 99, 287, 157, 705, 421, 1093, \ 
     139, 204, 14, 240, 179, 94, 139, 645, 670, 47, 520, 891, 450, 56, 964,   \
     1728, 99, 277, 356, 1628, 745, 364, 88, 112, 810, 816, 523, 401, 89,     \ 
     278, 917, 370, 53, 39, 90, 853, 356 ] 
x = sort(x_example)
y = linspace(0,1,len(x))

ax = subplot(1,1,1)
plots[w] = ax.plot(x,y, marker='o')

I am plotting Cumulative Distribution Functions, with a large number of data points. I am plotting a few lines on the same plot, which are identified with markers as it will be printed in black and white. What I would like are markers evenly spaced in the x-dimension. What I am getting is one marker per data point (and given the number of points, they all overlap)

I'm not sure if it's my understanding of how to plot well, or just a lack of understanding matplotlib. I can't find a 'marker frequency' setting.

An easy solution for one line would be to take every N'th value from the line, and use that as a separate line with linestyle='', but I would like the markers to be vertically aligned, and the different x arrays have different lengths.

# in reality, many thousands of values
x_example = [ 567, 460, 66, 1034, 275, 26, 628, 99, 287, 157, 705, 421, 1093, \ 
     139, 204, 14, 240, 179, 94, 139, 645, 670, 47, 520, 891, 450, 56, 964,   \
     1728, 99, 277, 356, 1628, 745, 364, 88, 112, 810, 816, 523, 401, 89,     \ 
     278, 917, 370, 53, 39, 90, 853, 356 ] 
x = sort(x_example)
y = linspace(0,1,len(x))

ax = subplot(1,1,1)
plots[w] = ax.plot(x,y, marker='o')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

计㈡愣 2024-08-24 14:12:18

您可以执行 plot(x,y,marker='o',markevery=5) 来标记每五个点,但我认为甚至没有任何内置支持设置标记间隔。您可以决定想要标记的 x 位置,使用例如 numpy.searchsorted 来查找位置落在哪些数据点之间,然后在相邻点之间进行插值以查找 y 坐标。

You can do plot(x,y,marker='o',markevery=5) to mark every fifth point, but I don't think there is any built-in support for setting marks at even intervals. You could decide on the x locations where you want the marks, use e.g. numpy.searchsorted to find which data points the locations fall between, and then interpolate between the neighboring points to find the y coordinates.

二手情话 2024-08-24 14:12:18

“markevery”可以采用不同的输入类型,
正如文档中所述:浮点数将标记之间的距离指定为屏幕空间中轴对角线的一部分。
例如,markevery=0.1 将沿 x 轴制作 10 个等距标记
或markerevery=(0.1,0.1) 将创建一个诊断性相等的距离标记。

The "markevery" can take different input type,
As it is said in the documentaion: A float specifies the distance between markers as a fraction of the Axes diagonal in screen space.
So for example markevery=0.1 will make 10 equally distanced marker along x-axis
or markerevery=(0.1,0.1) will make a diagnolly equall distanced markers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文