简体   繁体   English

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

[英]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.

相关问题 Python:如何使用大型数据集创建 3D 散点图 plot 并为每个点分配不透明度/透明度? - Python: How to create a 3D scatter plot and assign an opacity/transparency to each point, with a large dataset? 如何在matplotlib中为散点图中的每个点绘制不同深浅的颜色? - How to plot different shades of a color for each point in a scatter plot in matplotlib? Matplotlib 散点图,每个点都有不同的文本 - Matplotlib scatter plot with different text at each point 如何控制python散点图中每个点的颜色和不透明度? - How can I control the color and opacity of each point in a python scatter plot? 指定散点图中每个点的颜色(matplotlib) - Specify color of each point in scatter plot (matplotlib) 在每个数据点使用不同的文本散布 plot - Scatter plot with different text at each data point 如何在使用MatPlotLib制作的散点图中为不同的点指定不同的颜色? - How do I assign different dots different colors in a scatter plot made with MatPlotLib? 如何使用 matplotlib 将线从 0,0 添加到每个散点 plot 点? - How to add lines from 0,0 to each scatter plot point using matplotlib? 如何在matplotlib中绘制具有不同边缘颜色的散点图? - How to do a scatter plot with different edgecolor in matplotlib? matplotlib:如何在一个网格中绘制多个散点图,其中每个图基于单独的列表具有不同的颜色? - matplotlib: How to plot multiple scatter plots in one grid where each plot is different color based on a separate list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM