添加后,是否可以更改Cartopy中对象的颜色?

时间:2018-11-17 23:03:38

标签: python-3.x cartopy

问题

我正在使用#include <stdio.h> int strlength(char* str); int main() { char *str; int comp; printf("Please enter the string: "); scanf("%s", str); printf("The length of the string is: %d\n", strlength(str)); return 0; } int strlength(char *str) { int length = 0; while(*str != '\0') { length++; str++; } return length; } 用Python绘制一些国家。为此,我正在使用cartopy函数,如下所示:

add_geometry

我希望能够更改已添加的几何对象的颜色。这样一来,我可以在动画国家/地区改变颜色的情况下,而不必每帧重新绘制所有内容。例如,所有国家都将以白色开头,然后一个接一个地变成蓝色。

但是,添加对象后,似乎无法找到改变颜色的方法。

通常有效的

使用maplotlib中的常规绘图,我会这样做:

geo = ax.add_geometries(geometry,facecolor='ghostwhite', edgecolor='black',crs=data_transf)

为什么在这里不起作用

对于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 中添加的set_color中的FeatureArtist没有cartopy功能。实际上,似乎add_geometries的属性colorfacecolor,...甚至不存在,如对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 个属性(或类似属性)。

1 个答案:

答案 0 :(得分:0)

Cartopy界面中绝对缺少此功能。您介意在Cartopy issue tracker上发布问题吗?

作为一种解决方法,您可以修改私有属性_kwargs,该属性似乎可以正常工作:

import cartopy.feature as cfeature
f = ax.add_feature(cfeature.STATES)
f._kwargs['edgecolor'] = 'blue'

注意::这是使用私有API,因此可能会更改/中断而不会发出任何警告。这只是让您动起来的解决方法,但我强烈建议您报告此问题,以便可以向Cartopy添加适当的解决方案。