notebook: notebook not showing matplotlib plot

Hi,

in the last days I started to have issues with my notebooks not showing some plots - I get outputs like [<matplotlib.lines.Line2D at 0x16b6dc2e8>] (similarly to #1620 )

In particular, I have a plot disappearing when I add labels such as plt.xlabel - without that it’s shown regularly

I always run %matplotlib inline at the beginning of my notebooks

Any idea of what is happening?

Thanks for your support.

ps: on safari 11.0.3 and notebook 5.4.1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 20
  • Comments: 37 (1 by maintainers)

Most upvoted comments

Hi. I like to set it “all”. Finally, I found that you can put a semicolon after “plt.show()”… That’s great.

ok,

plt.show(); seem to solve the issue (for now) – thanks @junhaowww !

Splitting matplotlib statements into multiple Jupyter input cells may cause nothing to appear. Check if all your statements are in the same cell.

well,

apparently plt.show(); doesn’t seem to work always…no idea what’s going on…

ok, it seems that this problem disappears when I comment (do not run)

from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"

( which I actually really like, as I don’t have to print(my_out) at every line …anyways )

… any idea if there is a conflict there and how to avoid it?

Thanks

ok, it seems to be unrelated to those shell settings. It’s probably related to the matplotlib backend settings

I usually use:

%matplotlib inline
sns.set_context('notebook')
%config InlineBackend.figure_format = 'retina'

in a simple example I am working for instance,

plt.hist(my_panads_series) did not work, even with those settings disabled, while my_panads_series.hist() did … again, no idea …

ps: I am on mac os 10.13.4, matplotlib 2.2.2, notebook 5.4.1

this link is useful, It worked for me https://github.com/matplotlib/ipympl

I see. You can add ; to the last line of codes. For example:

  1. normal case
a = 1
b = 1
# do plotting
plt.show();
  1. special case
a = 1
b = 1
# do plotting
plt.show()
# if plt.show() is not on the last line
a = 2;       # like this

Your plot has been export successfully but without showing in jupyter. %matplotlib inline , insecting this will make it .

Unfortunately, I think this is the downside of trying to make plot displaying ‘just work’ - when it doesn’t work, it can be pretty mystifying to figure out what’s going wrong. I don’t have any great ideas at the moment, sorry. 😦

In jupyter notebook it works, in jupiter lab it does not… why???

multiple Yes! Put all in one cell and the pic came out!

Try putting all plotting commands in one cell, with the last command in the cell being:

plt.show()

Sometimes this is not necessary — the plot will show regardless, but it seems to fix the problem for me.

as soon as I add other plotting commands such as plt.xlabel(my_label) no plot is shown with both plt.show() or plt.show(); (I also tried to put plt.xlabel(my_label); which does not work either …)

… there must be some sort of conflict with those commands and the interactiveshell…

I got this issue in my environment. When I combine code in all cells into one. It works! But I believe that this issue is not yet solved.

Hey I’m experiencing this issue still. This issue appears not to be resolved. I’m using the latest version of python and when I try to get plots it either doesn’t show or gives a textual description of the plot!d Capture