内容简介:翻译自:https://stackoverflow.com/questions/6028675/setting-color-range-in-matplotlib-patchcollection
PatchCollection
.
问题是matplotlib似乎会自动将颜色范围缩放到数据值的最小值/最大值.如何手动设置颜色范围?例如.如果我的数据范围是10-30,但我想将其缩放到5-50的颜色范围(例如与另一个图比较),我该怎么做?
我的绘图命令看起来与api示例代码中的相同: patch_collection.py
colors = 100 * pylab.rand(len(patches)) p = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.4) p.set_array(pylab.array(colors)) ax.add_collection(p) pylab.colorbar(p) pylab.show()
set_clim
方法.
作为一个完整的例子:
import matplotlib import matplotlib.pyplot as plt from matplotlib.collections import PatchCollection from matplotlib.patches import Circle import numpy as np # (modified from one of the matplotlib gallery examples) resolution = 50 # the number of vertices N = 100 x = np.random.random(N) y = np.random.random(N) radii = 0.1*np.random.random(N) patches = [] for x1,y1,r in zip(x, y, radii): circle = Circle((x1,y1), r) patches.append(circle) fig = plt.figure() ax = fig.add_subplot(111) colors = 100*np.random.random(N) p = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.4) p.set_array(colors) ax.add_collection(p) plt.colorbar(p) plt.show()
现在,如果我们在调用plt.show(…)之前在某处添加p.set_clim([5,50])(其中p是补丁集合),我们得到:
翻译自:https://stackoverflow.com/questions/6028675/setting-color-range-in-matplotlib-patchcollection
以上所述就是小编给大家介绍的《python – 在matplotlib patchcollection中设置颜色范围》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 颜色搭配及颜色科学
- 使用golang写一个高性能端口扫描器,支持IP范围,端口号范围
- CSS教程:图片使用混合模式和颜色叠加filter滤镜,改变PNG图标颜色
- jQuery日期范围选择器
- OpenGL ES入门: 渲染金字塔 - 颜色、纹理、纹理与颜色混合填充以及GLKit实现
- ThinkPHP模板范围判断标签使用
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Sovereign Individual
James Dale Davidson、William Rees-Mogg / Free Press / 1999-08-26 / USD 16.00
Two renowned investment advisors and authors of the bestseller The Great Reckoning bring to light both currents of disaster and the potential for prosperity and renewal in the face of radical changes ......一起来看看 《The Sovereign Individual》 这本书的介绍吧!