使用比数据点少的标记进行绘图(或者是绘制CDF的更好方法?)[matplotlib或常规绘图帮助] [英] Plot with fewer markers than data points (or a better way to plot CDFs?) [matplotlib, or general plotting help]

查看:166
本文介绍了使用比数据点少的标记进行绘图(或者是绘制CDF的更好方法?)[matplotlib或常规绘图帮助]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制具有大量数据点的累积分布函数.我正在同一条绘图上绘制几条线,这些线用标记标识,因为它将以黑白打印.我想要的是在x维度上均匀间隔的标记.我得到的是每个数据点一个标记(并且鉴于点的数量,它们全部重叠)

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)

我不确定这是我对如何正确绘制的理解还是对matplotlib的缺乏了解.我找不到标记频率"设置.

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.

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

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')

推荐答案

您可以执行plot(x,y,marker='o',markevery=5)来标记第五个点,但是我认为没有内置支持以均匀间隔设置标记.您可以使用例如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.

这篇关于使用比数据点少的标记进行绘图(或者是绘制CDF的更好方法?)[matplotlib或常规绘图帮助]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆