X Tutup
Skip to content

Using plt.ion with startup commands #8160

@Kodiologist

Description

@Kodiologist

I'm running matplotlib 2.0.0, installed with pip, with the TkAgg backend and Python 3.5.2 on Lubuntu 16.10. If I open the Python REPL and type

>>> import matplotlib.pyplot as plt
>>> plt.ion()
>>> plt.plot([1, 2, 3])

then, as I expect, a Tk window with the figure appears after the final command.

However, if I instead do:

>>> import matplotlib.pyplot as plt
>>> plt.plot([1, 2, 3])
>>> plt.ion()
>>> plt.plot([4, 5, 6])

no figure window appears, even after the last command. It seems that running any plotting command before plt.ion prevents it from having its usual effect.

You might ask why I don't just make sure to type plt.ion() first. The answer is I have a function named matplotlib_prelude containing some startup commands that's run automatically when I start the Python REPL, and if I call plot.ion before this, a figure window will open even though I haven't plotted anything yet (and indeed I may not use matplotlib at all this session). Here's what I have in matplotlib_prelude at the moment:

import matplotlib.pyplot as plt
plt.tick_params(right = False, top = False)
plt.gca().spines["top"].set_visible(False)
plt.gca().spines["right"].set_visible(False)

This used to work before matplotlib 2: I called plt.ion first, and these startup lines didn't cause a figure window to open.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup