FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

artists zorder is ignored during animations · Issue #2959 · matplotlib/matplotlib · GitHub

Repository navigation

artists zorder is ignored during animations #2959

Closed

Description

In animated plots, the order at wich artists are drawn is determined by their position in the sequence returned by the animation function, despite their own "zorder" property.

Activity

  1. tacaswell commented on Apr 8, 2014

    Member

    Can you provide a minimal example which demonstrates this?

  2. WeatherGod commented on Apr 8, 2014

    Member

    This might be an effect of the blitting, if it is turned on. Try turning
    off blitting, as that will force a redraw of each artist object at their
    respective zorder.

    On Tue, Apr 8, 2014 at 10:12 AM, Thomas A Caswell
    notifications@github.comwrote:

    Can you provide a minimal example which demonstrates this?

    Reply to this email directly or view it on GitHubhttps://github.com//issues/2959#issuecomment-39852248
    .

  3. sebtoun commented on Apr 8, 2014

    Author

    Here is a code sample showing the issue (indeed turning off blitting restores a correct behaviour): blue circle should be in front of red one

    # -*- coding: utf-8 -*-
    import matplotlib.pyplot as plt
    import matplotlib.animation as animation
    from math import sin, pi
    fig = plt.figure()
    ax = fig.add_subplot(111, autoscale_on=False, 
                 xlim=(-2, 2), ylim=(-2, 2), aspect='equal')
    circle_fg = plt.Circle((-0.5,0),1,color='b')
    circle_fg.set_zorder(2)
    ax.add_artist(circle_fg)
    circle_bg = plt.Circle((0.5,0),1,color='r')
    circle_bg.set_zorder(1)
    ax.add_artist(circle_bg)
    def init():
        circle_fg.radius = 0
        circle_bg.radius = 0
        return circle_fg, circle_bg
    def animate(i):
        circle_fg.radius = 1
        circle_bg.radius = 1
        
        circle_fg.center = (-0.5, -sin(i*2*pi/50))
        circle_bg.center = (0.5, sin(i*2*pi/50))
        # order in return sequence determine draw order with blit=True, 
        # zorder property seems to be ignored
        return circle_fg, circle_bg
    ani = animation.FuncAnimation(fig, animate, 200,
        interval=40, blit=True, init_func=init)
        
    plt.show()
    

    By the way, is there a cleaner way to define init function ? I alway have to put dubious code in it in order to get a clean empty background...

  4. tacaswell commented on Jun 29, 2014

    Member

    It is slightly better to just tweak the visibility in the init function.

    Tagging this for 1.4.x, but I think this behavior should be documented, but not changed. With blitting the animated artists must be on top of all the other artists in the axes so we are already treating the animated artists differently.

  5. added this to the v1.4.x milestone on Jun 29, 2014
  6. modified the milestones: v1.4.x, v1.4.1 on Sep 3, 2014
  7. modified the milestones: , v1.4.x on Feb 7, 2015
  8. modified the milestones: , on Jul 17, 2015
  9. modified the milestones: , on Oct 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL