matplotlib / ipympl

Matplotlib Jupyter Integration
https://matplotlib.org/ipympl/
BSD 3-Clause "New" or "Revised" License
1.57k stars 227 forks source link

(Auto-)Resize plots that start too large #431

Open mueslo opened 2 years ago

mueslo commented 2 years ago

Describe the issue

Plots by default are sometimes too large, and the right side is cut off (e.g. when using the sexy Jupyter Lab side-by-side rendering or just using a small screen. Obviously you then want to resize them. However, since the resize handle is at the bottom right, it is also not visible. So the only current solution is to manually change the figure size in the code and re-run until it is visible. Not an ideal solution; sometimes you may not have direct access to the code creating the figure.

Some possible solutions:

The current state is rather frustrating.

Example: image

Versions

jupyterlab==3.2.8 jupyterlab-widgets==1.0.2 ipympl==0.8.7 ipywidgets==7.6.5

mueslo commented 2 years ago

One quick temporary (Jupyter Lab side) workaround is the following;

in CSS (widget.css) add

.p-Widget, .lm-Widget {
  overflow-x: auto;
}

or alternatively:

.jupyter-matplotlib {
  overflow-x: visible; /* or auto; was hidden */
}
.jupyter-widgets {
  overflow-x: hidden; /* or auto; was visible*/
}

or

.jp-OutputArea-child {
  overflow-x: auto;
}

This gives you back the horizontal scrollbar when the figure overflows the cell horizontally.

ianhi commented 2 years ago

Thanks for reporting and suggesting a fix @mueslo !

I think this has the same core cause as https://github.com/matplotlib/ipympl/issues/242

one point of clarification: does the scroll bar only show up when the widget is partially clipped, or is it always present? If the former then I like the solution of modifying the jupyter-matplolitb class - we should not be messing with jupyterlab or lumino css as that will have broad sideeffects. Do you also need to change the .jupyter-widgets class?

mueslo commented 2 years ago

With my solutions it only shows up when necessary, i.e. when the output exceeds the jupyter lab output cell size. But I have noticed that JupyterLab never displays horizontal scroll bars, so maybe it should be fixed there instead of here (and all of these fixes would require changes outside of ipympl also)

ianhi commented 2 years ago

But I have noticed that JupyterLab never displays horizontal scroll bars, so maybe it should be fixed there instead of here.

I think both are an option. It's much easier to push a new release here than in jlab so we can do a fix here and you can also open an issue there. Would you be willing to make a PR with your fix?

mueslo commented 2 years ago

If the former then I like the solution of modifying the jupyter-matplolitb class - we should not be messing with jupyterlab or lumino css as that will have broad sideeffects. Do you also need to change the .jupyter-widgets class?

Sadly it seems like modifying .jupyter-widgets is also necessary in that case, I havent found any way to make the horizontal scrollbar appear in just .jupyter-matplotlib without setting .jupyter-widgets overflow-x to hidden.

VladimirIvonin commented 1 year ago

Hello, @mueslo! Could you tell me, please, where can I find widget.css file?

Firestar-Reimu commented 5 months ago

图片

I have the same problem here that the image is too large, what is the solution now? Where is the widget.css? @mueslo