在散点图中将值绘制为符号的最简单方法?

发布于 2024-09-04 01:05:31 字数 849 浏览 2 评论 0原文

在回答我之前关于修复 4D 数据散点图像的色彩空间的问题时,Tom10 建议将值绘制为符号,以便仔细检查我的数据。一个好主意。我过去运行过一些类似的演示,但我一生都找不到我记得的演示非常简单。

那么,将数值绘制为散点图中的符号(而不是“o”)的最简单方法是什么? Tom10 建议 plt.txt(x,y,value) - 这是许多示例中使用的实现。然而,我想知道是否有一种简单的方法可以从我的数字数组中评估“价值”?可以简单地说: str(valuearray) 吗?

您是否需要一个循环来评估绘图的值,如 matplotlib 演示部分中针对 3D 文本散点的建议情节

他们的示例生成:

替代文字
(来源:sourceforge.net

但是,他们'在评估位置以及根据数据更改文本方向方面正在做一些相当复杂的事情。那么,有没有一种可爱的方法来绘制 x,y,C 数据(其中 C 是通常被视为绘图数据中的颜色的值 - 但我希望制作符号)?

再说一遍,我认为我们对此有一个公平的答案 - 我只是想知道是否有更简单的方法?

In an answer to an earlier question of mine regarding fixing the colorspace for scatter images of 4D data, Tom10 suggested plotting values as symbols in order to double-check my data. An excellent idea. I've run some similar demos in the past, but I can't for the life of me find the demo I remember being quite simple.

So, what's the easiest way to plot numerical values as the symbol in a scatter plot instead of 'o' for example? Tom10 suggested plt.txt(x,y,value)- and that is the implementation used in a number of examples. I however wonder if there's an easy way to evaluate "value" from my array of numbers? Can one simply say: str(valuearray) ?

Do you need a loop to evaluate the values for plotting as suggested in the matplotlib demo section for 3D text scatter plots?

Their example produces:

alt text
(source: sourceforge.net)

However, they're doing something fairly complex in evaluating the locations as well as changing text direction based on data. So, is there a cute way to plot x,y,C data (where C is a value often taken as the color in the plot data- but instead I wish to make the symbol)?

Again, I think we have a fair answer to this- I just wonder if there's an easier way?

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

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

发布评论

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

评论(1

暮年 2024-09-11 01:05:31

我见过的最简单的方法是:

for x, y, val in zip(x_array, y_array, val_array):
    plt.text(x, y, val)

另外,顺便说一句,您建议使用 str(valarray) ,正如您可能已经注意到的那样,这不起作用。要将数字数组转换为字符串序列,您可以使用

valarray.astype(str)

获取 numpy 数组,或者

[str(v) for v in valarray]

获取 Python 列表。但即使将 valarray 作为正确的字符串序列,plt.text 也不会迭代其输入。

The easiest way I've seen to do this is:

for x, y, val in zip(x_array, y_array, val_array):
    plt.text(x, y, val)

Also, btw, you suggested using str(valarray), and this, as you may have noticed doesn't work. To convert an array of numbers to a sequence of strings you could use

valarray.astype(str)

to get a numpy array, or,

[str(v) for v in valarray]

to get a Python list. But even with valarray as a proper sequence of strings, plt.text won't iterate over it's inputs.

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