繁体   English   中英

Python matplotlib:如何为散点图中的每个点分配不同的不透明度?

[英]Python matplotlib: How to assign a different opacity to each point in a scatter plot?

我想在散点图上列出一系列要点。 每一点都由我对它的关心程度来加权。 我希望根据我对散点图的关注程度来设置不透明度。

这是我目前的尝试,但失败了

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

plt.scatter行失败,但异常

AttributeError:'tuple'对象没有属性'view'

tcaswell是正确的。 我只需要添加.tolist()

colors = weights.apply(lambda x: (0,0,1,x)).tolist()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM