简体   繁体   English

matplotlib绘制多个散点图,每个散点图由不同的三次变量着色

[英]matplotlib Plot multiple scatter plots, each colored by different thrid variable

I'm trying to plot multiple pairs of data on a single scatter plot, each colored by a different third variable array. 我正在尝试在单个散点图上绘制多对数据,每对数据由不同的第三变量数组着色。 The coloring seems to work for the first plot, then fails for the second and third. 着色似乎适用于第一个图,然后不适用于第二个和第三个图。

Any help would be appreciated 任何帮助,将不胜感激

import matplotlib.pyplot as plt

jet=plt.get_cmap('jet')

x = [1,2,3,4]
y = [1,2,3,4]
z = [1,1,1,1]

a = [2,3,4,5]
b = [1,2,3,4]
c = [2,2,2,2]

d = [3,4,5,6]
e = [1,2,3,4]
f = [3,3,3,3]

plt.scatter(x, y, s=100, c=z, cmap=jet)
plt.scatter(a, b, s=100, c=c, cmap=jet)
plt.scatter(d, e, s=100, c=f, cmap=jet)

plt.clim(0,5)
plt.colorbar()
plt.show()

I have removed the plt.clim(0,5) line and added minimal and maximal values for all plots and that seems to work. 我删除了plt.clim(0,5)行,并为所有图添加了最小值和最大值,这似乎可行。

import matplotlib.pyplot as plt

jet=plt.get_cmap('jet')

x = [1,2,3,4]
y = [1,2,3,4]
z = [1,1,1,1]

a = [2,3,4,5]
b = [1,2,3,4]
c = [2,2,2,2]

d = [3,4,5,6]
e = [1,2,3,4]
f = [3,3,3,3]

plt.scatter(x, y, s=100, c=z, vmin=1, vmax=5, cmap=jet)
plt.scatter(a, b, s=100, c=c, vmin=1, vmax=5, cmap=jet)
plt.scatter(d, e, s=100, c=f, vmin=1, vmax=5, cmap=jet)

plt.colorbar()
plt.show()

The problem is that your colormap is being renormalized for each of your plot commands. 问题在于您的色图正在针对每个绘图命令进行重新规范化。 Also. 也。 As a matter of style, jet is basically never the right colormap to use. 就样式而言, jet永远都不是正确使用的颜色图。 So try this: 所以试试这个:

import matplotlib.pyplot as plt

jet=plt.get_cmap('coolwarm')

x = [1,2,3,4]
y = [1,2,3,4]
z = [1,1,1,1]

a = [2,3,4,5]
b = [1,2,3,4]
c = [2,2,2,2]

d = [3,4,5,6]
e = [1,2,3,4]
f = [3,3,3,3]

plt.scatter(x, y, s=100, c=z, cmap=jet, vmin=0, vmax=4)
plt.scatter(a, b, s=100, c=c, cmap=jet, vmin=0, vmax=4)
plt.scatter(d, e, s=100, c=f, cmap=jet, vmin=0, vmax=4)

plt.clim(0,5)
plt.colorbar()
plt.show()

Makes a nice plot: 做出一个不错的情节: 在此处输入图片说明

暂无
暂无

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

相关问题 matplotlib:如何在一个网格中绘制多个散点图,其中每个图基于单独的列表具有不同的颜色? - matplotlib: How to plot multiple scatter plots in one grid where each plot is different color based on a separate list? Matplotlib:具有多组单独垂直散点图的散点 plot - Matplotlib: Scatter plot with multiple groups of individual vertical scatter plots Matplotlib 散点图返回不同版本的不同图 - Matplotlib Scatter Plot Returns Different Plots in Different Versions Matplotlib 散点图,每个点都有不同的文本 - Matplotlib scatter plot with different text at each point 如何使用matplotlib在同一窗口中绘制多个散点图? - How to plot multiple scatter plots in the same window with matplotlib? 如何在matplotlib中为散点图中的每个点绘制不同深浅的颜色? - How to plot different shades of a color for each point in a scatter plot in matplotlib? 使用 matplotlib 避免具有不同颜色的多个簇的重叠散点图 - Avoiding overlaid scatter plots of multiple clusters with different color using matplotlib Matplotlib:创建一个散点图,其中每个点都根据其在数据集中的实例数进行着色(加权) - Matplotlib: creating a scatter plot where each point is colored (weighted) based on its count of instances in the dataset 一个 plot 上的多个散点图 - Multiple scatter plots on one plot 在matplotlib上的散点图中为每个系列设置不同的颜色 - Setting different color for each series in scatter plot on matplotlib
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM