[Matplotlib-devel] New Axes.lines interface

Gregor Mönke tensionheadx at gmail.com
Wed Feb 23 04:29:39 EST 2022


I am using interactive matplotlib figures inside a PyQT application (
https://github.com/tensionhead/pyboat), and often I want to re-draw lines
upon new user input onto an Axis which also has other elements (generated
by imshow() in my case). For the last years that basically worked like this:

def draw():
    # there was already a line drawn
    if ax.lines:
        ax.lines = []
    # (re-)draw

Now (matplotlib 3.5.1) this does not seem to work anymore, as I get an
Attribute error:
AttributeError: can't set attribute 'lines'

When I inspect the ax.lines I formerly got a list holding
`matplotlib.lines.lines2D` objects, now I have a <Axes.ArtistList of 1
lines>. I looked into the API (
https://matplotlib.org/devdocs/api/axes_api.html#other), and what I got
from there is that this is a transitional class and I should use this 'as
it was a tuple already`. I am stuck here now, I tried to `del` the whole
ax.lines attribute or setting it to an empty tuple but nothing worked.

How can I remove a line from an axis without clearing it? Thanks for your

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/matplotlib-devel/attachments/20220223/43cc8c56/attachment.html>

More information about the Matplotlib-devel mailing list