【发布时间】:2010-07-23 16:35:33
【问题描述】:
我使用plot(x,y,'r') 绘制一个红色圆圈。 x 和 y 是数组,当配对为 (x,y) 并绘制时,所有点形成一条圆线。
fill(x,y,'r') 绘制一个以红色填充(或着色)的红色圆圈。
如何保持圆圈内部为白色,但将圆圈外部填充到轴边界?
我曾考虑使用fill_between(x_array, y1_array, y2_array, where),但在玩了一会儿之后,我认为这不适用于我的 x,y 数组。我想fill_between() 在圆外,在由轴边界定义的正方形内,但我不认为fill_between() 有能力......我确信我可以将它变成一个完整类型的增量问题x 和 delta y 将归零,但我不愿意。
如果有人看到我在fill_between() 中遗漏了什么,请告诉我。
我真正需要做的就是屏蔽掉二维数组中的数字,这些数字位于用 x 和 y 创建的圆的边界之外,这样当二维数组被视为内部的颜色图或轮廓时圆圈将成为图像,而外部将被涂白。
这可以通过二维数组的掩蔽技术来实现吗?喜欢使用 masked_where() 吗?我还没有研究它,但会的。
有什么想法吗?谢谢
编辑 1:这是我有权表明我认为可以解释我的问题的内容。
from pylab import *
from matplotlib.path import Path
from matplotlib.patches import PathPatch
f=Figure()
a=f.add_subplot(111)
# x,y,z are 2d arrays
# sometimes i plot a color plot
# im = a.pcolor(x,y,z)
a.pcolor(x,y,z)
# sometimes i plot a contour
a.contour(x,y,z)
# sometimes i plot both using a.hold(True)
# here is the masking part.
# sometimes i just want to see the boundary drawn without masking
# sometimes i want to see the boundary drawn with masking inside of the boundary
# sometimes i want to see the boundary drawn with masking outside of the boundary
# depending on the vectors that define x_bound and y_bound, sometimes the boundary
# is a circle, sometimes it is not.
path=Path(vpath)
patch=PathPatch(path,facecolor='none')
a.add_patch(patch) # just plots boundary if anything has been previously plotted on a
if ('I want to mask inside'):
patch.set_facecolor('white') # masks(whitens) inside if pcolor is currently on a,
# but if contour is on a, the contour part is not whitened out.
else: # i want to mask outside
im.set_clip_path(patch) # masks outside only when im = a.pcolor(x,y,z)
# the following commands don't update any masking but they don't produce errors?
# patch.set_clip_on(True)
# a.set_clip_on(True)
# a.set_clip_path(patch)
a.show()
【问题讨论】:
标签: python matplotlib