[英]Python matplotlib: How to assign a different opacity to each point in a scatter plot?
I have a series of points I want to put on a scatter plot. 我想在散点图上列出一系列要点。 Each point is weighted by how much I care about it.
每一点都由我对它的关心程度来加权。 I want the dot on the scatter plot to have an opacity set according to how much I care about it.
我希望根据我对散点图的关注程度来设置不透明度。
This is my current attempt, which fails 这是我目前的尝试,但失败了
import pandas as pd
import matplotlib.pyplot as plt
x = pd.Series([0, .2, .4, .6, .8, 1])
y = pd.Series([0, .2, .4, .6, .8, 1])
weights = pd.Series([0, .2, .4, .6, .8, 1])
# this is me trying to create RGBA tuples from the weights
colors = weights.apply(lambda x: (0,0,1,x))
plt.scatter(x, y, c=colors)
plt.show()
The plt.scatter line fails with the exception plt.scatter行失败,但异常
AttributeError: 'tuple' object has no attribute 'view' AttributeError:'tuple'对象没有属性'view'
tcaswell is correct. tcaswell是正确的。 I simply need to add .tolist()
我只需要添加.tolist()
colors = weights.apply(lambda x: (0,0,1,x)).tolist()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.