Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Handle HiDPI displays in WebAgg/NbAgg backends #5383
Conversation
mdboom
added the
needs_review
label
Nov 2, 2015
mdboom
added this to the
next bug fix release (2.0.1)
milestone
Nov 2, 2015
QuLogic
and 1 other
commented on an outdated diff
Nov 2, 2015
|
Rebased |
|
Does this work correctly if the user changes the DPI (not even really sure if that is possible anyway). The way I see it, the original dpi could never get updated? |
|
With Chrome, I can't find a way to change the "devicePixelScale" dynamically. It can be set with a commandline argument, but that implies restarting the browser. With Firefox, it can be set dynamically through This also performs fine under |
|
If I move a window from my external Non high dpi to my internal Retina monitor |
|
@jenshnielsen: That's a good point. I only have HiDPI monitors. I'd be curious what happens for you if you're able to test that. My best guess is that if you move from lodpi to hidpi the image will be pixelated. If you move from hidpi to lodpi the image will be downsampled (but appear at a reasonable total size). Neither of which are the end of the world. I guess we could try to trap the change and adapt on the fly. It seems at least theoretically possible: https://stackoverflow.com/questions/28905420/window-devicepixelratio-change-listener |
|
If I understand the code correctly it will get the DPI every time a new figure is created? Otherwise this is really nice |
|
This also manifests it self in that the coordinates in the lower right corner are wrong. |
|
I've fixed the issues with the coordinates and the rubberband. This still has potential issues when moving the browser from a lo to hi-res screen, but I don't have a way of testing that. |
mdboom
added some commits
Nov 2, 2015
|
Thanks I will test out the moving when I'm back with my external monitors |
|
Did some testing.
I think this is fine and there is no need to do anything more elaborate. Did you push the fix for rubberband? I dont see the any commits newer than d0b16a1 which is 12 days old |
|
Sorry -- recent changes pushed now. |
|
The rubberband and coordinates look right now. I am still seeing the issue where the figure grows in size when stopped and converted to a static figure. I guess the right dpi is not set for the static figure. |
|
Ah -- See that DPI change now, too. Let me see what can be done. At least for me, the static figure is scaled up by the browser (i.e. not using the full DPI of the display). We should fix that, but I suspect that might require tweaking something in IPython. |
|
IPython at least used to have some hidpi support ipython/ipython#3381 not sure where that lives now |
|
I see -- maybe we can add that flag for the user, since we already know they are retina. (Of course, multiple clients connected to the same kernel will be a problem -- but we have that problem in NbAgg anyway). |
mdboom
modified the milestone: next major release (2.0), next bug fix release (2.0.1)
Dec 6, 2015
|
I was playing around with this and it seems to me that we can solve it by doing something like mpl.figure.prototype.handle_close = function(fig, msg) {
var width = fig.canvas.width/mpl.ratio
fig.root.unbind('remove')
// Update the output cell to use the data from the current canvas.
fig.push_to_output();
var dataURL = fig.canvas.toDataURL();
// Re-enable the keyboard manager in IPython - without this line, in FF,
// the notebook keyboard shortcuts fail.
IPython.keyboard_manager.enable()
$(fig.parent_element).html('<img src="' + dataURL + '" width="' + width + '">');
fig.close_ws(fig, msg);
}I.E explicitly setting the width according to the dpi ratio. This obviously needs some more work |
|
And a similar modification in push_to_output mpl.figure.prototype.push_to_output = function(remove_interactive) {
// Turn the data on the canvas into data in the output cell.
var width = this.canvas.width/mpl.ratio
var dataURL = this.canvas.toDataURL();
this.cell_info[1]['text/html'] = '<img src="' + dataURL + '" width="' + width + '">';
} |
|
I put in a pull request with the changes in mdboom/matplotlib#15 With those changes I think this is ready to go |
|
Im happy to merge this now. It is tagged agains 2.0 but I'm not sure if we want to backport it? |
jenshnielsen
added a commit
that referenced
this pull request
Dec 10, 2015
|
|
jenshnielsen |
0a08ceb
|
jenshnielsen
merged commit 0a08ceb
into matplotlib:master
Dec 10, 2015
tacaswell
removed the
needs_review
label
Dec 10, 2015
|
Happy to backport if anyone thins we should |
|
I can see this going either way for backporting. @tacaswell: Wanna be the tie-breaker? |
|
|
jenshnielsen
added a commit
to jenshnielsen/matplotlib
that referenced
this pull request
Aug 18, 2016
|
|
jenshnielsen + jenshnielsen |
5bf037e
|
jenshnielsen
referenced
this pull request
Aug 18, 2016
Open
mpl_connect does not write output to jupyter notebook #6948
tacaswell
added a commit
that referenced
this pull request
Aug 20, 2016
|
|
tacaswell |
0bf79ea
|
jenshnielsen
referenced
this pull request
Aug 31, 2016
Closed
Initial HiDPI support for qt5agg backend #6389
QuLogic
added a commit
to QuLogic/matplotlib
that referenced
this pull request
Oct 16, 2016
|
|
jenshnielsen + QuLogic |
9111ee2
|
|
Backported to v2.x via #6956. |
QuLogic
added a commit
to QuLogic/matplotlib
that referenced
this pull request
Oct 16, 2016
|
|
QuLogic |
734b702
|
mdboom commentedNov 2, 2015
Fix #5381.
Tested on Firefox/Chrome/Safari on Linux/Mac. Anyone able to do Windows testing?