You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our plotting functions should work well in different environments, most prominently
jupyter notebooks
an interactive python shell, such as ipython.
Whether the plot is shown or not should be configurable via settings and/or context manager. But we should come up with reasonable defaults.
When ax is provided
Never show the figure. In that case we assume that the user is building a larger figure consisting of multiple panels. They should invoke plt.show() once they are ready. It is debatable whether or not we should return the figure object in that case (see jupyter notebook case below).
Jupyter notebooks
Jupyter notebooks automatically show a Figure object that is returned by the last statement in a cell. Otherwise it can be shown with display(fig):
plot_umap()
print("foo")
doesn't show the figure, but
display(plot_umap())
print("foo")
and
print("foo")
plot_umap()
do.
This matches my expectation quite well, as it would be the same for a function returning e.g. a pandas data frame.
The function should also call plt.close() before returning the figure, otherwise too many open figures accumulate.
Interactive environments.
In an interactive environment, I'd expect
pl.umap()
to actually
show the plot
clean up once the plot is closed (otherwise too many open figures accumulate).
This can be achieved by plt.show(). Figure.show() does not work if the plot has been closed before using plt.close() as we should do within the function (unless ax is provided).
@flying-sheep, this is why I proposed to call either plt.close() or plt.show() depending on the backend (see also #1).
Would be great to hear your thoughts on this! Also are there any other relevant environments that I'm missing?
The text was updated successfully, but these errors were encountered:
Our plotting functions should work well in different environments, most prominently
ipython
.Whether the plot is shown or not should be configurable via settings and/or context manager. But we should come up with reasonable defaults.
When
ax
is providedNever show the figure. In that case we assume that the user is building a larger figure consisting of multiple panels. They should invoke
plt.show()
once they are ready. It is debatable whether or not we should return the figure object in that case (see jupyter notebook case below).Jupyter notebooks
Jupyter notebooks automatically show a
Figure
object that is returned by the last statement in a cell. Otherwise it can be shown withdisplay(fig)
:doesn't show the figure, but
and
do.
This matches my expectation quite well, as it would be the same for a function returning e.g. a pandas data frame.
The function should also call
plt.close()
before returning the figure, otherwise too many open figures accumulate.Interactive environments.
In an interactive environment, I'd expect
to actually
This can be achieved by
plt.show()
.Figure.show()
does not work if the plot has been closed before usingplt.close()
as we should do within the function (unlessax
is provided).@flying-sheep, this is why I proposed to call either
plt.close()
orplt.show()
depending on the backend (see also #1).Would be great to hear your thoughts on this! Also are there any other relevant environments that I'm missing?
The text was updated successfully, but these errors were encountered: