GR.jl icon indicating copy to clipboard operation
GR.jl copied to clipboard

Cropped image

Open masenka31 opened this issue 4 years ago • 13 comments

Hi, I'm unable to fix a cropping issue. When I plot, the picture is cropped from left and bottom, making it impossible to see xlabel, ylabel and full y ticks number.

image

Numbers on the y axis should be 0.98 etc. Trying to fix it with margin attribute doesn't work. Any suggestions?

masenka31 avatar Jun 08 '20 09:06 masenka31

I tried this and get the following result:

using Plots
y = 0.98 .+ rand(10) .* 0.01
plot(y)

Could you please provide your example? Screen Shot 2020-06-08 at 11 41 40

jheinen avatar Jun 08 '20 09:06 jheinen

Still the same even with this example. I'm on Linux Lustre and the gksqt is not working properly - but I don't have the rights to install additional dependencies. Therefore I'm saving it directly do pdfs. I guess I'll be using PlotlyJS, which is working properly.

masenka31 avatar Jun 08 '20 09:06 masenka31

I also experience this issue. It occurs when generating the plots in a headless environment. Generating them in an environment with a head works fine.

Octogonapus avatar Jun 30 '20 15:06 Octogonapus

In a headless environment, pls try

% env GKSwstype=100 julia
julia> using Plots
julia> y = 0.98 .+ rand(10) .* 0.01
julia> plot(y)

and use savefig(...) to generate output.

jheinen avatar Jun 30 '20 16:06 jheinen

I get this image: test

Octogonapus avatar Jun 30 '20 16:06 Octogonapus

Which Plots and GR version are you using - I can't reproduce this.

] st Plots
] st GR
import GR
GR.version()
versioninfo()

jheinen avatar Jun 30 '20 16:06 jheinen

For me, it's

julia> Plots.GR.version()
"0.50.0.post27"

(@v1.4) pkg> st Plots
Status `/usr/local/lib/julia/environments/v1.4/Project.toml`
  [91a5bcdd] Plots v1.5.0

(@v1.4) pkg> st GR
Status `/usr/local/lib/julia/environments/v1.4/Project.toml`
  [28b8d3ca] GR v0.50.1 #master (https://github.com/jheinen/GR.jl.git)

and the PNG (or whatever output) is ok: Screen Shot 2020-06-30 at 18 13 30

jheinen avatar Jun 30 '20 16:06 jheinen

Plots version 1.5.0. I don't have GR installed directly but it is in the manifest at version 0.50.1.

I bet you can't reproduce it because you are opening a terminal on a machine with a head. That image you posted definitely looks like it is running in an environment with a head. Try SSH'ing into a machine and running Julia over the SSH connection.

Octogonapus avatar Jun 30 '20 16:06 Octogonapus

I did that:

% ssh ifflinux   
Last login: Tue Jun 30 18:20:41 2020 from 93.205.94.18
jheinen@iff1702:~% env GKSwstype=100 julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.4.2 (2020-05-23)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using Plots; y = 0.98 .+ rand(10) .* 0.01; plot(y); savefig("t.pdf")
julia> 
jheinen@iff1702:~% logout
Connection to ifflinux closed.
jheinen@mb-pro ~ % scp -p ifflinux:t.pdf .
t.pdf                                                             100% 7394   299.8KB/s   00:00    
jheinen@mb-pro ~ % open t.pdf

t.pdf

jheinen avatar Jun 30 '20 16:06 jheinen

Did you download a recent run-time: ENV["GRDIR"] = ""; ] build GR", or, are you probably using an old GR version? What's the value of GRDIR after importing GR? (ENV["GRDIR"])

jheinen avatar Jun 30 '20 16:06 jheinen

The version of GR in the Manifest.toml file is 0.50.1. For some reason, the version of Plots.GR is 0.50.0.

julia> ENV["GRDIR"]
"/home/salmon/.julia/packages/GR/Atztx/src/../deps/gr"

Octogonapus avatar Jun 30 '20 16:06 Octogonapus

Hi, I am having a related issue. I realized that when I adjust the size of the plotting area using ``gr(size=...)'' , it does not leave space for the axis labels. It seems like there is one good size/proportion and that any deviation from it will crop the axis labels. For example, when I do

using Plots
gr(size=(400,200))
y = 0.98 .+ rand(10) .* 0.01
plot(y)
xaxis!("X axis"); yaxis!("Y axis")

I get good

But when I do

using Plots
gr(size=(600,100))
y = 0.98 .+ rand(10) .* 0.01
plot(y)
xaxis!("X axis"); yaxis!("Y axis")

I get cropped

Does anyone have an idea what this could be due to? Thanks for the help,

jeanpauphilet avatar Oct 30 '21 11:10 jeanpauphilet

This problem can't be fixed in GR. Plots should use the gr_inqtext function to obtain the exact bounding box of the text to be drawn and reserve enough space for the labels and annotations.

jheinen avatar Oct 30 '21 19:10 jheinen