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

Pyplot image cut off #220

Closed
swt30 opened this issue May 4, 2016 · 8 comments
Closed

Pyplot image cut off #220

swt30 opened this issue May 4, 2016 · 8 comments

Comments

@swt30
Copy link
Contributor

swt30 commented May 4, 2016

Plots.savefig is cutting off some annotations which run off the edge of the axes, even when the figure is adjusted with PyPlot.subplots_adjust.
plot

In matplotlib I'd add bbox_inches="tight" to the savefig command to fix this. Should this line be uncommented? https://github.com/tbreloff/Plots.jl/blob/3c09921cbd4da44b36fb5a6ed03e0a528d0e38f8/src/backends/pyplot.jl#L1113

@tbreloff
Copy link
Member

tbreloff commented May 4, 2016

Should this line be uncommented?

Well it's certainly there for a reason! I don't know if it should be uncommented... I think the reason I took it out is because it semi-arbitrarily changed the size of the plot, and I wasn't happy about it.

I think the better solution is to allow for better fine-tuning of the commands. This is sort of related to the request for a DPI keyword (#173). I'm open to suggestions, but I want to avoid solutions that are too hacky.

@tbreloff
Copy link
Member

tbreloff commented May 4, 2016

And of course... you can always just run those commands yourself with the bbox_inches included if you're desperate...

@swt30
Copy link
Contributor Author

swt30 commented May 4, 2016

I'm with you on semi-arbitrarily changing the size of the plot not being ideal. One could argue that it's on the user to not place annotations that run off the edge of the figure canvas anyway. The problem is that the behaviour is inconsistent between backends: in PlotlyJS the axes are resized automatically to hold the annotation, in Gadfly you have to manually adjust the axis limits to see the annotation, and in matplotlib you can either do that or use subplots_adjust to add white space without extending the axes - but then we run into the issue of needing to save it with bbox_inches="tight". I suspect that this issomething that will be very annoying to get working in a consistent fashion. So I might just have to accept that I'll have to go to the backend-specific commands to make this kind of tweak, which is fine by me.

@tbreloff
Copy link
Member

tbreloff commented May 4, 2016

one more thing... you can set the horizontal and vertical alignment pretty easily. in this case you might want your annotations to be :right and :bottom. see: http://plots.readthedocs.io/en/latest/examples/pyplot/#annotations

@tbreloff
Copy link
Member

In "Plots 0.7" you can do something like:

using Plots; pyplot()
plot(rand(10), series_annotations=["fdkhjsdkh" for i=1:10], left_margin = 15mm, right_margin = 15mm)

@swt30
Copy link
Contributor Author

swt30 commented May 27, 2016

Thanks Tom, that's awesome!

@Amend-1634
Copy link

In "Plots 0.7" you can do something like:

using Plots; pyplot()
plot(rand(10), series_annotations=["fdkhjsdkh" for i=1:10], left_margin = 15mm, right_margin = 15mm)
  1. Hi, I tried plot(...,bottom_margin=100px) or plot(...,left_margin = 15mm, right_margin = 15mm) but get the report: "px, mm not defined. My Julia version is v"1.2.0".
  2. gr(display_type=:inline) before plotting help a bit but the margin of the figure still crops parth of the annotation out.
  3. savefig("D:\mutation1",bbox_inches='tight') report "ERROR: syntax: invalid character literal"

Are there any other solutions based on updated Julia?

@daschw
Copy link
Member

daschw commented Dec 26, 2019

px, mm, etc. are no longer exported. You can either do using Plots.Measures or use Plots.mm instead.

Jonas-a-Zimmermann pushed a commit to Jonas-a-Zimmermann/Plots.jl that referenced this issue Oct 29, 2024
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

No branches or pull requests

4 participants