Skip to content

Conversation

pelson
Copy link
Member

@pelson pelson commented Mar 23, 2016

Without this, it isn't possible to render:

def main():
    plt.plot(range(4))
    plt.show()

if __name__ == '__main__':
    main()

without the caching mechanism getting tripped up by the fact that only one image is produced.

@pelson pelson force-pushed the plot_directive_show branch from 2830d33 to 7e943c7 Compare March 23, 2016 17:40
@mdboom
Copy link
Member

mdboom commented Mar 23, 2016

Isn't it the case that no plot is produced in the example, since __name__ != __main__ in the context in which it's run?

I worry about looking specifically for plt.show(), since there's all kinds of other ways that could get called. But I don't quite understand the problem here to begin with -- maybe there's another way to solve it.

@pelson
Copy link
Member Author

pelson commented Mar 26, 2016

Isn't it the case that no plot is produced in the example, since name != main in the context in which it's run?

No, these run just fine for me. Probably because of https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/sphinxext/plot_directive.py#L517

I worry about looking specifically for plt.show(), since there's all kinds of other ways that could get called.

Agreed. That is already pretty fundamentally required though: https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/sphinxext/plot_directive.py#L323-L343

@tacaswell tacaswell modified the milestone: 2.1 (next point release) Jul 16, 2016
@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Aug 29, 2017
@anntzer
Copy link
Contributor

anntzer commented Jan 5, 2018

I think the correct fix is to run the code in a context where plt.show is patched to handle all the saving, rather than trying to split the code ourselves -- this should allow arbitrary execution paths to be handled...

@QuLogic
Copy link
Member

QuLogic commented Jan 5, 2018

Well, cartopy uses sphinx-gallery now, so...

@tacaswell tacaswell removed this from the v2.2 milestone Jan 7, 2018
@tacaswell
Copy link
Member

Closing this as it is ~2 years old and from @QuLogic 's comment I take it that the motivation for this no longer exists.

I suspect @anntzer 's suggestion of patching plt.show is a better way to handle this as well.

@tacaswell tacaswell closed this Jan 7, 2018
@pelson pelson deleted the plot_directive_show branch January 11, 2018 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants