Using object oriented interface in interactive mode?

Benjamin Root <ben.root-GrrYUJ3DTa8@...1455...> writes:

···

On Sunday, August 5, 2012, Nikolaus Rath wrote:

Hello,

The following code shows the plot right away as expected:

# python
Python 2.7.3rc2 (default, Apr 22 2012, 22:30:17)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.__version__
'1.1.1rc2'
>>> import matplotlib.pyplot as plt
>>> plt.interactive(True)
>>> plt.plot(range(10))
[<matplotlib.lines.Line2D object at 0x2ce7790>]

This, however, opens a window but the graph never shows up:

# python
Python 2.7.3rc2 (default, Apr 22 2012, 22:30:17)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> plt.interactive(True)
>>> fig = plt.figure()
>>> ax = fig.add_subplot(1,1,1)
>>> ax.plot(range(10))
[<matplotlib.lines.Line2D object at 0x3055d90>]
>>>

Does interactive mode only apply to the plot commands in pyplot?

Is there a method I can call in this case to "refresh" the window and
show the plot?

For seem reason, calling plt.axes() has the desired effect, but this is
probably a side effect that I really should not rely on, right?

Correct, I think you want plt.draw().

Thanks, that works! But why is it necessary? Does interactive mode only
apply to direct pyplot.* commands?

Thanks,

   -Nikolaus

--
»Time flies like an arrow, fruit flies like a Banana.«

  PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C

Not quite. It is that the pyplot commands have a “draw_if_interactive” call as a final step. This way, matplotlib can defer drawing until it is really needed. This improves responsiveness. When in OO mode, the training wheels come off and the developer is responsible for issuing draw() calls when they need to.

Cheers!

Ben Root

···

On Sunday, August 5, 2012, Nikolaus Rath wrote:

Benjamin Root <ben.root-GrrYUJ3DTa8@…1455…> writes:

On Sunday, August 5, 2012, Nikolaus Rath wrote:

Hello,

The following code shows the plot right away as expected:

python

Python 2.7.3rc2 (default, Apr 22 2012, 22:30:17)

[GCC 4.6.3] on linux2

Type “help”, “copyright”, “credits” or “license” for more information.

import matplotlib

matplotlib.version

‘1.1.1rc2’

import matplotlib.pyplot as plt

plt.interactive(True)

plt.plot(range(10))

[<matplotlib.lines.Line2D object at 0x2ce7790>]

This, however, opens a window but the graph never shows up:

python

Python 2.7.3rc2 (default, Apr 22 2012, 22:30:17)

[GCC 4.6.3] on linux2

Type “help”, “copyright”, “credits” or “license” for more information.

import matplotlib.pyplot as plt

plt.interactive(True)

fig = plt.figure()

ax = fig.add_subplot(1,1,1)

ax.plot(range(10))

[<matplotlib.lines.Line2D object at 0x3055d90>]

Does interactive mode only apply to the plot commands in pyplot?

Is there a method I can call in this case to “refresh” the window and

show the plot?

For seem reason, calling plt.axes() has the desired effect, but this is

probably a side effect that I really should not rely on, right?

Correct, I think you want plt.draw().

Thanks, that works! But why is it necessary? Does interactive mode only

apply to direct pyplot.* commands?

Thanks,

-Nikolaus