|
From: Jae-Joon L. <lee...@gm...> - 2012-10-19 04:36:56
|
On Tue, Oct 16, 2012 at 4:04 PM, 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?
QuadContourSet does not (I think it should), but LineCollection
instances in QuadContourSet.collections does. Below is a quick
example.
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(100)-50
arr = (x**2 + x[:,np.newaxis]**2)**.5
cont = plt.contour(arr)
col1 = cont.collections[3] # contour line to clip with.
clip_path = col1.get_paths()[0] # Note that col1 may have multiple paths.
for col in cont.collections:
col.set_clip_path(clip_path, col1.get_transform()) # set clip_path
for individual LineCollection instances.
plt.show()
|