根据第三个变量改变散点图中的标记样式 [英] Changing marker style in scatter plot according to third variable

查看:161
本文介绍了根据第三个变量改变散点图中的标记样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个多列字典。我想绘制两列,随后根据第三和第四列改变标记的颜色和样式。



我在pylab散点图中更改标记样式, 。我的方法,适用于颜色,不幸的是不适用于标记样式。

  x = [1,2,3,4 ,5,6] 
y = [1,3,4,5,6,7]
m = ['k','l','l','k','j'
m [i] = m [i] .replace('j','o')
m [ i] = m [i] .replace('k','x')
m [i] = m [i] .replace('l','+')

plt .scatter(x,y,marker = m)
plt.show()


解决方案

问题是标记只能是一个值,而不是标记列表,因为 / code> parmeter。



您可以按标记值进行分组,以便您的x和y列表具有相同的标记并绘制它们: / p>

  xs = [[1,2,3],[4,5,6]] 
ys = [[ 1,2,3],[4,5,6]]
m = ['o','x']
for i in range(len(xs)):
plt。 scatter(xs [i],ys [i],marker = m [i])
plt.show()

或者你可以绘制每一个点(我不推荐):

  x = [1,2,3,4, 5,6] 
y = [1,3,4,5,6,7]
m = ['k','l','l','k','j',' ']

mapping = {'j':'o','k':'x','l':'+'}

len(x)):
plt.scatter(x [i],y [i],marker = mapping [m [i]])
plt.show()


I am dealing with a multi-column dictionary. I want to plot two columns and subsequently change color and style of the markers according to a third and fourth column.

I struggle with changing the marker style in the pylab scatter plot. My approach, which works for color, unfortunately does not work for marker style.

x=[1,2,3,4,5,6]
y=[1,3,4,5,6,7]
m=['k','l','l','k','j','l']

for i in xrange(len(m)):
    m[i]=m[i].replace('j','o')
    m[i]=m[i].replace('k','x')
    m[i]=m[i].replace('l','+')

plt.scatter(x,y,marker=m)
plt.show()

解决方案

The problem is that marker can only be a single value and not a list of markers, as the color parmeter.

You can either do a grouping by marker value so you have the x and y lists that have the same marker and plot them:

xs = [[1, 2, 3], [4, 5, 6]]
ys = [[1, 2, 3], [4, 5, 6]]
m = ['o', 'x']
for i in range(len(xs)):
    plt.scatter(xs[i], ys[i], marker=m[i])
plt.show()

Or you can plot every single dot (which I would not recommend):

x=[1,2,3,4,5,6]
y=[1,3,4,5,6,7]
m=['k','l','l','k','j','l']

mapping = {'j' : 'o', 'k': 'x', 'l': '+'}

for i in range(len(x)):
    plt.scatter(x[i], y[i], marker=mapping[m[i]])
plt.show()

这篇关于根据第三个变量改变散点图中的标记样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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