简体   繁体   English

如何在Matplotlib中将值转换为圆形的颜色信息?

[英]How to convert values into color information for circle in matplotlib?

I am trying to convert values into color information in Colormap. 我正在尝试将值转换为Colormap中的颜色信息。 I have z values and would like to map z value into circle shape. 我有z值,并想将z值映射为圆形。 For example, I have a coordinate (xi,yi) and would like to draw a circle centering this coordinate with z value mapped into colormap. 例如,我有一个坐标(xi,yi),并想绘制一个以该坐标为中心的圆,并将z值映射到颜色图中。 However, it is not drawing any circle. 但是,它没有画任何圆圈。 Below is my code. 下面是我的代码。

r = 100
color_map = cm.Oranges
norm = Normalize(vmin=1, vmax=100)
rgba = color_map(norm(zi))

CS = plt.Circle((xi, yi), r, color=rgba[0])

You have couple of issues actually. 您实际上有几个问题。 You didn't create any axes and you are using color map incorrectly. 您没有创建任何轴,并且使用的颜色贴图不正确。 So, create your circles and note how color_map is used. 因此,创建您的圈子并注意如何使用color_map。 Then add it to a created axes object. 然后将其添加到创建的轴对象。

import matplotlib.pyplot as plt

r = 100
color_map = plt.get_cmap("Oranges")
circle1 = plt.Circle((0, 0), 0.2, color=color_map(0.66))
circle2 = plt.Circle((0.5, 0.5), 0.2, color=color_map(0.45))
circle3 = plt.Circle((1, 1), 0.2, color=color_map(0.2), clip_on=True)

fig, ax = plt.subplots()
ax.add_artist(circle1)
ax.add_artist(circle2)
ax.add_artist(circle3)

在此处输入图片说明

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM