Skip to content

Conversation

@jcheng5
Copy link
Collaborator

@jcheng5 jcheng5 commented Oct 25, 2023

The primary goal of this PR is to provide an easy way to influence the width/height of the output_plot that's implicitly generated by displaying a @render.plot. There will also be a separate @output_args decorator that will let you set any argument on any implicit output, but the specific case of plot width/height seems like such a common case that it's worth the effort to make it dead simple.

Two additional effects of this PR: the pixel dimensions of the image generated on the server side can now be influenced by @render.plot(width=float, height=float), or if that is not specified, by using matplotlib/plotnine to set the Figure size (in inches). And it is now possible to set the DPI of a figure using matplotlib/plotnine, which changes the size of text.

This isn't going to work because I forgot matplotlib shouldn't be
loaded preemptively by us before user code has run. But I wanted
to snapshot a working version before trying to fix that problem.
@jcheng5 jcheng5 requested a review from wch October 26, 2023 05:41
@jcheng5 jcheng5 marked this pull request as ready for review October 26, 2023 05:42
@wch wch merged commit fee9752 into main Oct 26, 2023
@wch wch deleted the render-plot-size branch October 26, 2023 15:24
@wch
Copy link
Collaborator

wch commented Oct 26, 2023

I just merged -- but note that we should have a changelog entry for this PR.

jcheng5 added a commit that referenced this pull request Oct 26, 2023
This fixes a bug introduced by #783, which was intended (in part)
to allow render.plot code to set plot sizes by using matplotlib
figure sizing. That code assumed that only explicit user code
would cause the figure size to differ from matplotlib's default
figure size (plt.rcParams["figure.figsize"]). But that's not true
for seaborn, which likes to set its own sizes, which we then
misidentified as being a high priority size directive that we
should obey.

https://seaborn.pydata.org/tutorial/function_overview.html#specifying-figure-sizes

This change removes the logic that looks at whether the figure
size changed. Instead, render.plot width/height can be set to 0
to cause the matplotlib figure size to be honored. However, we're
not going to be emphasizing that in our docs, at least for now.
schloerke added a commit that referenced this pull request Nov 2, 2023
* main: (56 commits)
  Add actions step for nightly reporting -> Testrail (#774)
  Remove unused entry in manifest
  Bump version to 0.6.0.9000
  Use latest htmltools
  Bump version to v0.6.0; Rearrange news to have API changes last
  Tweaks from testing
  Fix default width/height with implicit plot output (#792)
  Update deps (#794)
  Remove deprecated 'name' parameter from `Outputs` (#791)
  api(ui): Drop `toggle_` methods. Consolidate update accordion methods. Stronger typing for `layout_sidebar(sidebar)` and `page_sidebar(sidebar)` (#788)
  bug(sidebar): Revert sidebar icon back to chevron (#789)
  For `input_action_button`, default to having whitespace around button (#758)
  Remove output from template app (#775)
  Add output_args and suspend_display decorators (#786)
  Update value_box; Update to bootstrap 5.3; Update htmldeps (#772)
  tests: add sidebar test (#787)
  Seaborn plots should fill their output_plot (#785)
  Kwargs to uvicorn run (#780)
  Add width and height arguments to `@render.plot` (#783)
  gitgnore dist/
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants