[Matplotlib-devel] What is draw_path's transform's destination?

Rob McDonald rob.a.mcdonald at gmail.com
Mon Apr 1 10:27:34 EDT 2019


For the record, I was able to resolve this issue as well.

This SO answer <https://stackoverflow.com/a/44552090> references a response
to a GitHub issue that gives the critical clue -- to_polygons has a
hard-coded resolution of 1 because it expects to work in pixel space.  So,
if I transform the Path before evaluating it, I get acceptable results.

Thanks,

Rob

On Sun, Mar 31, 2019 at 12:30 AM Rob McDonald <rob.a.mcdonald at gmail.com>
wrote:

> On Sat, Mar 30, 2019 at 11:51 PM Rob McDonald <rob.a.mcdonald at gmail.com>
> wrote:
>
>> Unfortunately, naively passing path_effects=[HatchedStroke()] to a
>> plt.contour() call doesn't 'just work'.  Is there a way to tell contour
>> lines to be drawn with a different path effect?
>>
>>
> OK -- so I made some progress on this...
>
> cp = plt.contour(x, y, z, colors=('k',), )
> plt.setp(cp.collections, path_effects=[HatchedStroke()])
>
> By and large works.  However, some of the hatches appear 'off' the lines.
> I believe this is because some of the contour Path's might be generated as
> Bezier curves (not simple polylines).  I need to interpolate along the path
> to generate hatches, but I don't have a full renderer -- and
> Path.interpolate doesn't do curves.  I currently do the following to get to
> polylines
>
> newpath = tpath.cleaned()
> polys = newpath.to_polygons(closed_only=False)
>
> Which generally works, but the default settings (deep inside agg from what
> I can tell (agg_curves.cpp etc.)) produce very coarse approximations that
> are rather unsatisfying.
>
> Is there a better way to get a polyline from an arbitrary Path (that may
> include Bezier curves)?  Someone has to have implemented a compound path
> evaluation routine...
>
> Alternately, is there a way to force contour to generate straight-line
> segments -- forcing the user to bump up the grid resolution if they want
> smooth curves?   Actually, that doesn't work.  I currently have an example
> with very fine resolution -- it appears that something in the Contour Path
> hierarchy is being clever and replacing the polyline segments with a smooth
> Bezier curve.  Possibly via a simplify call -- if there isn't a way to
> evaluate the true Path in draw_path, then perhaps there is a way to turn
> off the simplify step contour is doing...
>
> Rob
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20190401/a92050fe/attachment.html>


More information about the Matplotlib-devel mailing list