简体   繁体   English

如何控制python散点图中每个点的颜色和不透明度?

[英]How can I control the color and opacity of each point in a python scatter plot?

I'm looking to graph a 4D data set (X, Y, Z, intensity) using opacity to represent intensity. 我正在寻找一个使用不透明度表示强度的4D数据集(X,Y,Z,强度)的图形。 I also want the color to be dependent on the Z variable as well to better show depth. 我还希望颜色也取决于Z变量,以更好地显示深度。

Here is the relevant code so far, I am a novice when it comes to Python: 到目前为止,这是相关的代码,对于Python我是一个新手:

.
.
.
x_list #list of x values as floats
y_list #list of y values as floats
z_list #list of z values as floats
i_list #list of intensity values as floats

.
.
.

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

Axes3D.scatter(ax, x_list, y_list, z_list)
.
.
.

So how can I do this? 那我该怎么做呢?

I'm thinking the color could be a linear relationship between z_list and a color map (hsv for example), and opacity could be linear as well, i_list/max(i_list) or something along those lines. 我认为颜色可能是z_list和颜色图(例如hsv)之间的线性关系,而不透明度也可能是线性的,即i_list / max(i_list)或沿这些线的东西。

I would do something like the following: 我将执行以下操作:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# choose your colormap
cmap = plt.cm.jet

# get a Nx4 array of RGBA corresponding to zs
# cmap expects values between 0 and 1
z_list = np.array(z_list) # if z_list is type `list`
colors = cmap(z_list / z_list.max())

# set the alpha values according to i_list
# must satisfy 0 <= i <= 1
i_list = np.array(i_list)
colors[:,-1] = i_list / i_list.max()

# then plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x_list, y_list, z_list, c=colors)
plt.show()

Here's an example with x_list = y_list = z_list = i_list . 这是x_list = y_list = z_list = i_list You can choose any of the colormaps here or make your own : 您可以在此处选择任何颜色图,可以自己制作 在此处输入图片说明

暂无
暂无

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

相关问题 Python matplotlib:如何为散点图中的每个点分配不同的不透明度? - Python matplotlib: How to assign a different opacity to each point in a scatter plot? 如何手动为 plotly 散点图中的每个点着色? - How can I manually color each point in my scatter-plot in plotly? 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? 如何使用为每个点单独指定的颜色创建散点图? - How to create a scatter plot with color specified for each point individually? 指定散点图中每个点的颜色(matplotlib) - Specify color of each point in scatter plot (matplotlib) 如何在 plotly (python) 中根据我的数据集中的“颜色”列更改散点图点的颜色? - How can I change the color of my scatter plot points based on a "color" column in my dataset in plotly (python)? 如何分别为散点图着色? - How to color the point of a scatter plot separately? pandas - 散布 plot,每个点都有不同的颜色图例 - pandas - scatter plot with different color legend for each point 如何使用 pcolor(或 imshow)到 plot 以每个 X、Y 散点为中心的颜色映射正方形 - How to use pcolor (or imshow) to plot color mapped squares centered on each X,Y scatter point
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM