question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Figure is stretched to window size

See original GitHub issue

Jupyterlab 1.0 and ipympl 0.3.1 Regardless of what figsize is set to, the plot appears stretched, see screenshot. image

Temporary workaround: If you want the “traditional” fixed size figure, you can use the following figure() function instead of plt.figure(): https://gist.github.com/thomasaarholt/9841ce2424bc40e3165142764e960150

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:38 (25 by maintainers)

github_iconTop GitHub Comments

4reactions
allefeldcommented, Oct 21, 2019

Jupyter newcomer here, my unsolicited opinion:

I don’t really mind that the figure adjusts to the width of the notebook window. In data analysis, the more screen space one can give the visualization, the better.

I do however mind that the aspect ratio becomes weird. I would posit that the classic figure aspect ratio is 4:3, going up to 2:1 may make sense, but beyond that it becomes silly (except for special situations).

Is it possible to fix the aspect ratio, so as the figure becomes wider, it also becomes higher?

Or, assuming that the notebook window width corresponds to about 80 em, set the figure height to 60 em?

As I said, newbie here, so maybe what I’m saying doesn’t make sense: But why can’t the matplotlib figsize simply be used in the notebook? As I understand, it’s in inches, converted to pixels through a dpi value, and an html element size can also be specified in inches.

3reactions
SylvainCorlaycommented, Jul 30, 2019

About the current situation

  • So in jupyter-matplotlib / ipympl, figure.canvas is an instance of DOMWidget. Sizing and layout of DOMWidget are set by their layout attribute, which allow setting any CSS property impacting layout to the top-level DOM element.
  • The problem is that if the size is not hard-coded in pixels (or some other constant-size unit), then multiple views of the same figure will have different sizes if displayed in different contexts. This is what happens to bqplot figures currently for example.
  • A first issue with that approach is that figsize is not the thing setting the layout. Maybe a means to fix this would be to have figsize actually be tied to layout in the case of ipympl somehow.
  • The main issue is that for matplotlib, there is only really one figure size in the backend, and the update events when requesting the rendered png for one view is going to impact other views. The pixel ratio also poses an issue in the case of a jupyter notebook / voila dashboard being displayed with two different devices because the requested size takes this into account.

Now, in order for matplotlib to behave consistently with Jupyter widgets and respect the matplotlib API, we need to align fiction to reality, in one direction or the other.

  • An approach would be to subclass ipywidgets.Layout for the case of the matplotlib figure for it to only accept sizes in inches so that it makes sense for the figsize api. In that case, we could easily bind figsize to the layout attribute. A drawback of this approach is that laying out and aligning figures with other jupyter widgets may be very difficult or impossible since the correspondance between inches and other size units depends on the client - and a notebook that works well for one user may look completely different for another.
  • An approach would be for png requests from the backend to attach a view ID so that we can discriminate requests based on it. We would ignore the general rcparam figsize, but forcibly setting the figsize in inches for a figure would take precedence over the layout.

Thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can you change how a matplotlib figure/axes is stretched ...
But, when you resize the window, the figure stretches in such a way that there is a large empty space created on the...
Read more >
How to make figure window change size - MATLAB Answers
The figure window stopped responding to commands. The figure window size does not change when I try to resize it using set(gcf, [...
Read more >
Autocad - Stretch command (change window size - Fast tutorial!)
This video explains how to stretch and shrink figures. We use for that the command STRETCH in the section modify.
Read more >
How to fix a stretched/squished screen/desktop (Resolution)
Hello YouTube!Today Im going to show you how to fix your stretch /squished screen /desktop. (other words: Resolution )There are 2 ways to...
Read more >
Change the size of a picture, shape, text box, or WordArt
If you want to stretch, shrink, or just change the size of a picture (or shape), use the sizing handles or for more...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found