-2

I am using pandas to create a plot and I am seeing outputs from the code other than the plot.

How do I hide the output circled in red in the screenshot below?

screenshot

kbmsdev
  • 1
  • 4

1 Answers1

-1

In your scenario, assuming you don't want to hide the graph you're plotting, you just need to put a semi-colon in the end.

Like this:

barh.bar_label(visit_count_barh.containers[0]);
  • 1
    The explanation is that the last line of a Jupyter cell is special (given default settings). It tries to display the return value of that item, see [here](https://stackoverflow.com/questions/14506583/suppress-output-of-object-when-plotting-in-ipython/31792131#comment54913617_31792131). In your case, `barh.bar_label(visit_count_barh.containers[0])` is returning a list of the information about the labels. And that accounts for the red text your circles. Adding the semi-colon effectively adds another line that has nothing as a return value. – Wayne Feb 27 '23 at 18:44
  • @Wayne I actually didn't knew it was a behavior of the line itself, really interesting. I always assumed it was a behavior of the cell. Could just adding a line instead of the semi-colon do the trick to? – Rômulo Férrer Filho Feb 27 '23 at 19:19
  • 1
    Maybe the semi-colon does become some sort of cell-level signal these days? I thought based on [here](https://stackoverflow.com/a/36835741/8508004) it was linked to the last expression being special, but if you run the example there and add `a + 3;` as a line below `a` and `a+1` then nothing prints from that entire cell even with `InteractiveShell.ast_node_interactivity = "all"`? I would have expected only the `a + 3;` line to stop working with `InteractiveShell.ast_node_interactivity = "all"`. (last expression is the default for that setting.) – Wayne Feb 27 '23 at 19:42