【发布时间】:2018-11-17 23:03:38
【问题描述】:
问题
我正在使用cartopy 在 Python 中绘制一些国家/地区。为此,我使用了这样的add_geometry 函数:
geo = ax.add_geometries(geometry,facecolor='ghostwhite', edgecolor='black',crs=data_transf)
我希望能够更改已添加的几何对象的颜色。通过这种方式,我可以在国家/地区更改颜色的情况下制作动画,而无需每帧重绘所有内容。例如,所有国家/地区都会从白色开始,然后依次变为蓝色。
但是,我似乎找不到在添加对象后更改其颜色的方法。
通常有效的方法
在 maplotlib 中使用通常的情节我会这样做:
import matplolib.pyplot as plt
line, = plt.plot([1,2,3],[4,5,6],'red') #Plot in red
line.set_color('green') #Change the color to green
为什么它在这里不起作用
FeatureArtistfrom cartopy 添加add_geometries 没有set_colorfunction。事实上,color,facecolor,... 属性似乎甚至不存在于 FeatureArtist 中,如对 matplotlib.artist.getp 的调用所示。
对于情节,调用返回:
>>import matplotlib.artist as mart
>>mart.getp(line)
agg_filter = None
alpha = None
animated = False
antialiased = True
children = []
clip_box = TransformedBbox( Bbox(x0=0.0, y0=0.0, x1=1.0, ...
clip_on = True
clip_path = None
color = (1.0, 0.0, 0.0, 1.0)
contains = None
dash_capstyle = butt
dash_joinstyle = round
data = (array([1, 2, 3]), array([4, 5, 6]))
drawstyle = default
figure = Figure(640x476)
fillstyle = full
gid = None
in_layout = True
label = _line0
linestyle = -
linewidth = 1.5
marker = None
markeredgecolor = (1.0, 0.0, 0.0, 1.0)
markeredgewidth = 1.0
markerfacecolor = (1.0, 0.0, 0.0, 1.0)
markerfacecoloralt = none
markersize = 6.0
markevery = None
path = Path(array([[ 1., 4.], [ 2., 5.], ...
path_effects = []
picker = None
pickradius = 5
rasterized = None
sketch_params = None
snap = None
solid_capstyle = projecting
solid_joinstyle = round
transform = CompositeGenericTransform( TransformWrapper( ...
transformed_clip_path_and_affine = (None, None)
url = None
visible = True
xdata = [1 2 3]
xydata = [[ 1. 4.] [ 2. 5.] [ 3. 6.]]
ydata = [4 5 6]
zorder = 2
对于几何:
>>mart.getp(geo)
agg_filter = None
alpha = None
animated = False
children = []
clip_box = TransformedBbox( Bbox(x0=0.0, y0=0.0, x1=1.0, ...
clip_on = True
clip_path = None
contains = None
figure = Figure(1200x990)
gid = None
in_layout = True
label =
path_effects = []
picker = None
rasterized = None
sketch_params = None
snap = None
transform = CompositeGenericTransform( TransformWrapper( ...
transformed_clip_path_and_affine = (None, None)
url = None
visible = True
zorder = 1
如您所见,我无法更改 colorproperty(或类似的)。
【问题讨论】:
标签: python-3.x cartopy