在散点图中将值绘制为符号的最简单方法? [英] Easiest way to plot values as symbols in scatter plot?

查看:42
本文介绍了在散点图中将值绘制为符号的最简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

您是否需要一个循环来评估在 matplotlib 演示部分为
(来源:sourceforge.net)

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

再次,我认为我们对此有一个合理的答案-我只是想知道是否有更简单的方法?

解决方案

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

用于zip中的x,y,val的

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

此外,顺便说一句,您建议使用str(valarray),并且您可能已经注意到这是行不通的.要将数字数组转换为字符串序列,可以使用

  valarray.astype(str)

获取一个 numpy 数组,或者,

  [valarray中v的str(v)]

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

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:


(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?

解决方案

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.

这篇关于在散点图中将值绘制为符号的最简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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