Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give the option to show the figure after plot() #36

Open
AthKouloumvakos opened this issue May 26, 2023 · 3 comments
Open

Give the option to show the figure after plot() #36

AthKouloumvakos opened this issue May 26, 2023 · 3 comments

Comments

@AthKouloumvakos
Copy link

Currently, because plt.show() is called by default in plot() the figure is created there and this prevents the user to add more data in the plots after function returns.

It would be usefull to select plt.show() with a key.

@jgieseler
Copy link
Owner

We have the boolean option return_plot_object in solarmach.plot(). With that the user can get the matplotlib object and alter it, doesn't this already provide more or less the same functionality? It's for advanced users anyhow, while making it necessary to call plt.show() every time makes it more complicate for all users (including non-advanced ones). 🤔

@AthKouloumvakos
Copy link
Author

Using the example in the Jupyter notebook doing the following in the make plot section:

import numpy as np
import matplotlib.pyplot as plt

fig, ax = sm.plot(plot_spirals=plot_spirals, plot_sun_body_line=plot_sun_body_line, 
                  reference_vsw=reference_vsw, transparent=transparent, numbered_markers=numbered_markers,
                  long_offset=long_offset, return_plot_object=return_plot_object,
                  show_plot=False)
ax.plot(np.deg2rad(90), 1, 's', color='black', label='Arbritary')
plt.show()

will not show the extra point because plt.show() has been called prevously

@jgieseler
Copy link
Owner

I think the problem is in that case that you call plt.show(). If you use fig.show() instead (or just fig in a Jupyter Notebook), it will show the updated plot:
plot
But as you can see, it will also update the plotting range and don't update the legend. So the user would still need to adjust some things manually.

And this is independent of whether plt.show() has been called before or not. In fact, I just tried locally replacing

if _isstreamlit():
    import streamlit as st
    st.pyplot(fig)
else:
    plt.show()

if return_plot_object:
    return fig, ax

with

if _isstreamlit():
    import streamlit as st
    st.pyplot(fig)
    return
else:
    if return_plot_object:
        return fig, ax
    else:
        plt.show()
        return

In the latter case, fig, ax = sm.plot(return_plot_object=True) doesn't show the plot, while plt.show() and fig.show() show the same figure as before. So the only thing that would be gained from that change is that the figure is not shown "twice" and that the "usual" plt.show() would work. I don't really see any benefit from that, but also no reason not to introduce that if you think it makes things more clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants