I use plot(x,y,'r')
to plot a red circle. x and y are arrays such that when paired as (x,y) and plotted, all points form a circle-line.
fill(x,y,'r')
plots a red circle that is filled in (or colored in) red.
How can I keep the circle white on the inside, but fill outside the circle out to the axis boundaries?
I looked into using fill_between(x_array, y1_array, y2_array, where)
but after a little playing with it I don’t think that will work for my x,y arrays. I thought to fill_between()
outside the circle, and inside a square that is defined by the axis boundaries, but I don’t think fill_between()
is capable… I’m sure I could make it into an integral type of problem with delta x and delta y going to zero, but I’m not willing to.
If anyone can see that I’m missing something with fill_between()
please let me know.
All I am really needing to do is mask out numbers in a 2d array that are located beyond this boundary of the circle created with x and y, such that when the 2D array is viewed as a color plot, or contour, inside the circle will be the image, and outside will be white-ed out.
Can this be accomplished by a masking technique of the 2D array instead? Like by using masked_where()
? I haven’t looked into it yet, but will.
Any ideas? Thanks
Edit 1: Here is what i have permission to show that I think will explain my problem.
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()