1

On a jupyterhub notebook (python 3.8.5) and using matplotlib (version 3.3.2) I am trying to create a simple plot. The cell content is as follows:

import matplotlib.pyplot as plt

def plot_something(time_array, dependent_var, label="label"):
    plt.plot(time_array, dependent_var, label=label)
    plt.xlabel('Time (ms)')
    plt.ylabel(label)
plot_something([1,2,3], [4,5,6])

However, there is a strange scroll box drawn around the created image with a scrollbar at the right (i.e. you cannot see the whole image, you have to scroll!):

enter image description here

which does not happen for other matplotlib plots in the same notebook. The image shows the complete output cell (and you can see the upper part of the plot is missing. You need yo scroll up to see it).

How can I programatically avoid this strange box around the matplotlib plot?

P.S. I am not sure how to reproduce this problem. If I execute the code on top of the notebook it work fine, I get just the plot without that strange scroll box:

enter image description here

I also checked for differences in the actual displayed html code between these two cases. I did not any differences!

Alex
  • 41,580
  • 88
  • 260
  • 469

2 Answers2

2

That is because of scrolling. To change that, you can go to Cell > All Outputs > Toggle Scrolling or one of the other options until you get the desired result.

Rutger
  • 593
  • 5
  • 11
  • Yes hats that works. But how can I do it within the notebook? What command to use inside a cell? – Alex May 28 '21 at 08:47
  • You can (double) click on the left margin of the cell – Rutger May 28 '21 at 08:49
  • 1
    You don't understand. I want to remove that box / disable that box AUTOMATICALLY just by running the cell. Without user interaction, without the user clicking somewhere. I want to just execute that cell that creates the plot, and the plot is created without that weird scroll box. Without additional user interaction. Just by the code in the cell. – Alex May 28 '21 at 08:52
  • Ah ok. When I Googled "how to avoid scrolling in notebook" this was the first hit: https://stackoverflow.com/questions/41641205/how-to-avoid-output-into-scrollable-frames-in-jupyter-notebook/41646557 which seems to be the solution you are looking for. – Rutger May 28 '21 at 08:54
0

As an actual better solution which neither requires additional code nor user-interaction in the notebook is to check the metadata of the notebook itself. The metadata of the cell that shows the scroll box looks like

{
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "plot_timecourse(time, v_soma)"
   ]
  },

Just remove the scroll part, i.e. change it to

{
   "cell_type": "code",
   "execution_count": null,
   "metadata": {}
   "outputs": [],
   "source": [
    "plot_timecourse(time, v_soma)"
   ]
  },
Alex
  • 41,580
  • 88
  • 260
  • 469