在matplotlib中的散点图中固定颜色 [英] Fixing color in scatter plots in matplotlib

查看:688
本文介绍了在matplotlib中的散点图中固定颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修正多个散点图上的颜色范围,并在每个图中添加一个颜色条(每个图中都相同)。基本上,我正在修复轴和颜色空间等的所有方面,以便绘图可以眼睛直接比较。



对于我的生活,我不能似乎找出了固定颜色范围的所有各种方式。我试过vmin,vmax,但它似乎没有做任何事情,我也尝试了clim(x,y),似乎也不工作。



这必须在这里和那里,我不能是唯一一个想要比较图中的各种数据子集...所以,你如何固定的颜色,使每个数据保持它的颜色之间的地块并且由于子集的最大值/最小值的改变而不会被重新映射到不同的颜色。-v-整个集合?

解决方案

设置vmin和vmax应该这样做。



这里有一个例子:

  import matplotlib.pyplot as plt 

xyc = range(20)

plt.subplot(121)
plt.scatter(xyc [:13 ],xyc [:13],c = xyc [:13],s = 35,vmin = 0,vmax = 20)
plt.colorbar()
plt.xlim b $ b plt.ylim(0,20)

plt.subplot(122)
plt.scatter(xyc [8:20],xyc [8:20],c = xyc [8:20],s = 35,vmin = 0,vmax = 20)
plt.colorbar()
plt.xlim(0,20)
plt.ylim )

plt.show()

/ p>


I want to fix the color range on multiple scatter plots and add in a colorbar to each plot (which will be the same in each figure). Essentially, I'm fixing all aspects of the axes and colorspace etc. so that the plots are directly comparable by eye.

For the life of me, I can't seem to figure out all the various ways of fixing the color-range. I've tried vmin, vmax, but it doesn't seem to do anything, I've also tried clim(x,y) and that doesn't seem to work either.

This must come up here and there, I can't be the only one that wants to compare various subsets of data amongst plots... so, how do you fix the colors so that each data keeps it's color between plots and doesn't get remapped to a different color due to the change in max/min of the subset -v- the whole set?

解决方案

Setting vmin and vmax should do this.

Here's an example:

import matplotlib.pyplot as plt

xyc = range(20)

plt.subplot(121)
plt.scatter(xyc[:13], xyc[:13], c=xyc[:13], s=35, vmin=0, vmax=20)
plt.colorbar()
plt.xlim(0, 20)
plt.ylim(0, 20)

plt.subplot(122)
plt.scatter(xyc[8:20], xyc[8:20], c=xyc[8:20], s=35, vmin=0, vmax=20)   
plt.colorbar()
plt.xlim(0, 20)
plt.ylim(0, 20)

plt.show()

And the plot this produces:

这篇关于在matplotlib中的散点图中固定颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆