-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix display of images created by the jupyter engine #9538
Conversation
751340d
to
4285b70
Compare
We also need tests that check for the output so we don't regress later. You can pattern-match on the examples we have in _quarto:
tests:
html:
ensureFileRegexMatches:
...
ensureHtmlElements:
... Use |
Tests pass 🎉 - let me know if you need help with the |
Making plots with matplotlib, the dpi of the displayed image (`figure.dpi`) can be controlled independently of the dpi with which it is saved (`savefig.dpi`). If you want the same value for the two cases the recommended way to do it is to set `figure.dpi` to the desired numeric value, then have `savefig.dpi` reference the `figure.dpi`. This is a achieved with plt.rcParams["savefig.dpi"] = "figure" Is also the default value in matplotlib. When `savefig.dpi` is set to the same numeric value as `figure.dpi`, it may not apply because the matplotlib figure can be saved (and it is often useful to do so) outside the context in which it was created; in which case it would refer to another `savefig.dpi` value. Ref: has2k1/plotnine#773
(@has2k1 I added a merge commit for the changelog so that we can start running the test suite) Those tests look good, thank you! |
First this commit fixes an error where `"key"` is used instead of `key`. Images created by ipython display functions(which includes matplotlib plots) may have the desired display width and height in the metadata. When they do, we fallback to those values instead of none. After this commit, the display size of images in jupyter notebooks that are rendered by quarto should be exactly the same as the sizes in their original environment. fixes quarto-dev#9470
let width = metadataValue(kCellOutWidth, 0); | ||
let height = metadataValue(kCellOutHeight, 0); | ||
let width = metadataValue(kCellOutWidth, "width", 0); | ||
let height = metadataValue(kCellOutHeight, "height", 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cderv For the Jupyter kernel, I couldn't think of a case were the metadata
would contain KCellOutWidth="out-width"
& KCellOutHeight="out-height"
. Is this for future support?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed this. I don't know exactly - I'll look closer. Maybe it was placeholder in anticipation to bring out-width
and out-height
to Jupyter (as it is supported in knitr initially)
This PR makes quarto render Jupyter generated images to the same size as they are rendered in Jupyter native environments like jupyter-lab or notebook.
References: has2k1/plotnine#773, #9470