Skip to content
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 matplotlib image size #3274

Merged
merged 4 commits into from
Feb 21, 2023
Merged

Fix matplotlib image size #3274

merged 4 commits into from
Feb 21, 2023

Conversation

freddyaboulton
Copy link
Collaborator

@freddyaboulton freddyaboulton commented Feb 21, 2023

Description

Fixes #3210 . Modifies the matplotlib css so that max_height is not set (this was making all the plots tiny) and removes width so that the plot size reflects the python configuration.

You can test with outbreak_forecast and this demo:

import matplotlib
import matplotlib.pyplot as plt
import gradio as gr

matplotlib.use("Agg")

def make_plot(width, height):
    fig, ax = plt.subplots(figsize=(width, height))
    fruits = ['apple', 'blueberry', 'cherry', 'orange']
    counts = [40, 100, 30, 55]
    bar_labels = ['red', 'blue', '_red', 'orange']
    bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']

    ax.bar(fruits, counts, label=bar_labels, color=bar_colors)

    ax.set_ylabel('fruit supply')
    ax.set_title('Fruit supply by kind and color')
    ax.legend(title='Fruit color')
    fig.savefig(f"{width}_{height}.png")

    return fig

with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            width = gr.Slider(1, 10, step=1, value=1, label="width")
            height = gr.Slider(1, 10, step=1, value=1, label="height")
        with gr.Column():
            plot = gr.Plot()
    
    width.change(make_plot, [width, height], [plot])
    height.change(make_plot, [width, height], [plot])
    demo.load(make_plot, [width, height], [plot])

demo.launch()

Outbreak forecast before

image

Outbreak forecast after

image

test demo before

matplotlib_before

test demo after

matplotlib_after

Checklist:

  • I have performed a self-review of my own code
  • I have added a short summary of my change to the CHANGELOG.md
  • My code follows the style guidelines of this project
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

A note about the CHANGELOG

Hello 👋 and thank you for contributing to Gradio!

All pull requests must update the change log located in CHANGELOG.md, unless the pull request is labeled with the "no-changelog-update" label.

Please add a brief summary of the change to the Upcoming Release > Full Changelog section of the CHANGELOG.md file and include
a link to the PR (formatted in markdown) and a link to your github profile (if you like). For example, "* Added a cool new feature by [@myusername](link-to-your-github-profile) in [PR 11111](https://github.com/gradio-app/gradio/pull/11111)".

If you would like to elaborate on your change further, feel free to include a longer explanation in the other sections.
If you would like an image/gif/video showcasing your feature, it may be best to edit the CHANGELOG file using the
GitHub web UI since that lets you upload files directly via drag-and-drop.

@gradio-pr-bot
Copy link
Collaborator

All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-3274-all-demos

@freddyaboulton freddyaboulton force-pushed the 3210-matplotlib-image-size branch from c7935cb to 17701f3 Compare February 21, 2023 20:48
@freddyaboulton freddyaboulton marked this pull request as ready for review February 21, 2023 20:54
@abidlabs
Copy link
Member

So much nicer, LGTM!

Copy link
Member

@pngwn pngwn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@freddyaboulton
Copy link
Collaborator Author

Thanks for the reviews @pngwn @abidlabs !

@freddyaboulton freddyaboulton merged commit fa094a0 into main Feb 21, 2023
@freddyaboulton freddyaboulton deleted the 3210-matplotlib-image-size branch February 21, 2023 21:34
dawoodkhan82 pushed a commit that referenced this pull request Feb 22, 2023
* Fix matplotlib css

* CHANGELOG

* Undo lockfile
dawoodkhan82 added a commit that referenced this pull request Feb 23, 2023
* dropdown

* more dropdown updates

* dropdown styling + option visibility

* changelog

* notebook

* fix test

* Allow more image formats (#3225)

* add wildcard to image input

* simplify mime types

* changelog

* regen noteboks

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: pngwn <hello@pngwn.io>

* fix webcam mirroring (#3245)

* fix webcam

* changelog

* fix changelog

* fix changelog

* fix changelog

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* Add `interactive=False` mode to `gr.Button` (#3266)

* add interactive=False to button

* add interactive=True by default

* changelog

* fix frontend

* fix backend test

* formatting

* review changes

* LaTeX height fix (#3258)

* latex height fix

* changelog

* formatting

* em

* em

* accidentally added script (#3273)

* Adding a script to benchmark the queue (#3272)

* added benchmark queue script

* changelg

* fix instructions

* Fix matplotlib image size (#3274)

* Fix matplotlib css

* CHANGELOG

* Undo lockfile

* Add timeouts to queue messages (#3196)

* Fix + test

* Remove print statements + fix import for 3.7

* CHANGELOG

* Remove more print statements

* Add 60 second timeout for uploading data

* Fix test

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>

* icons

* separate options into component

* formatting

* changelog

* changelog

* fix ui tests

* formatting again...

* backend test fix

* format

* doc fixes

---------

Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: fienestar <fienestar@gmail.com>
Co-authored-by: pngwn <hello@pngwn.io>
Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
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.

Matplotlib images are really small
4 participants