|
From: Damon M. <dam...@gm...> - 2012-10-16 07:34:30
|
On Tue, Oct 16, 2012 at 8:04 AM, T J <tj...@gm...> wrote: > I'm interested in clipping the result of plt.contour (and > plt.contourf) to a patch. However, QuadContourSet does not have a > set_clip_path() method. Is there a way to do this? > > Here is an example plot that I have generated. > > http://imgur.com/pybIf > > For the curious, it plots contours of a function on the 2-simplex. > The way I've gone about computing this is, unfortunately, convoluted. > I generate a regular grid in 2D and treat each point as a projection > of a 3D probability vector into 2D. Then, I invert the projection so > that I have "distributions" and then compute the Z value for each > point. The contours are then calculated, but now, I need to clip > everything outside the triangle, as only points within the triangle > correspond to actual distributions. > > Is there a more direct way to calculate contours on a restricted set? > > Thanks. The contour functions support masked regions. I think that might be what you're looking for. Since the region you want to mask is a triangle, maybe even use a masked triangulated contour plot? Here's the call signature: http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.tricontour Does that help? -- Damon McDougall http://www.damon-is-a-geek.com B2.39 Mathematics Institute University of Warwick Coventry West Midlands CV4 7AL United Kingdom |