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

Precise figure sizing #519

Closed
avonmoll opened this issue Jul 25, 2016 · 3 comments · Fixed by #1906
Closed

Precise figure sizing #519

avonmoll opened this issue Jul 25, 2016 · 3 comments · Fixed by #1906
Milestone

Comments

@avonmoll
Copy link

I'm building a custom Gantt chart generator and need to be able to precisely control the figure AND axes sizes in order to get a matplotlib graph to line up with the Excel grid:
image

The problem is that in Plot.show() when the figure is saved, bbox_inches is set to 'tight' which basically undoes all my fine tuning of the axes position in Python. This behavior is probably desirable in most applications and situations and I'm considering just inheriting from Plot and overriding the show method. Is my situation too unique to account for in the xlwings library, or could/should the bbox_inches setting be settable by the user?

@avonmoll
Copy link
Author

As a side note - successive redraws of the plot force the image to have the same height and width as the image it's replacing, which in my case is undesirable (e.g. if a row were added to the task list).

Feel free to put all this on the back burner, I hacked my way around both of these items.

@fzumstein
Copy link
Member

Makes sense to me, yes...

@fzumstein
Copy link
Member

0.27.7 allows to set the savefig options via

sheet.pictures.add(image=myfigure, export_options={"bbox_inches": "tight", "dpi": 300})

Whether or not the updated picture should keep the exact dimensions of the previous picture is probably debatable, not sure. However, you can easily update a picture and change dimensions by deleting/inserting like so:

    if "mypic" in sheet.pictures:
        sheet.pictures["mypic"].delete()
    sheet.pictures.add(
        image=myfigure,
        name="mypic",
        anchor=sheet["A1"],
        export_options={"bbox_inches": "tight", "dpi": 80},
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants