plot_directive, context and multiple plots

Hi,

I am happily using `plot_directive`, but I've run into an
inconvenience when using the 'context' option. Consider this rst
file:

```

···

#######
A title
#######

.. plot::
    :context:

    import matplotlib.pyplot as plt
    plt.plot(range(10))

Then some text.

.. plot::
    :context:

    plt.figure()
    plt.plot(range(5), 'r')
```

In the second panel you see plots for both the first figure and the
second figure, because the underlying code is making this call:

        fig_managers = _pylab_helpers.Gcf.get_all_fig_managers()

to find all current figures, finding the first and the second figure,
and rendering both. I think this is unlikely to be what the user
expects (it confused me), but I wasn't sure what the best way to work
round it was. I considered adding another option like `:myfigs: true`
to the directive which would only pick up figures I create using the
current code block - is there a better way?

Cheers,

Matthew

Wouldn’t a better default be to just close all figures when they’re displayed? It can’t be common that someone wants to show the same plot repeatedly (and if they do that could have an option)…?

-n

···

On 14 Jul 2014 22:16, “Matthew Brett” <matthew.brett@…149…> wrote:

Hi,

I am happily using plot_directive, but I’ve run into an

inconvenience when using the ‘context’ option. Consider this rst

file:


#######

A title

#######



.. plot::

    :context:



    import matplotlib.pyplot as plt

    plt.plot(range(10))



Then some text.



.. plot::

    :context:



    plt.figure()

    plt.plot(range(5), 'r')

In the second panel you see plots for both the first figure and the

second figure, because the underlying code is making this call:

    fig_managers = _pylab_helpers.Gcf.get_all_fig_managers()

to find all current figures, finding the first and the second figure,

and rendering both. I think this is unlikely to be what the user

expects (it confused me), but I wasn’t sure what the best way to work

round it was. I considered adding another option like :myfigs: true

to the directive which would only pick up figures I create using the

current code block - is there a better way?

Cheers,

Matthew


Want fast and easy access to all the code in your enterprise? Index and

search up to 200,000 lines of code with a free copy of Black Duck

Code Sight - the same software that powers the world’s largest code

search on Ohloh, the Black Duck Open Hub! Try it now.

http://p.sf.net/sfu/bds


Matplotlib-devel mailing list

Matplotlib-devel@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-devel