Skip to content

Use Measure when setting plot size #501

@grero

Description

@grero

It seems like the size attribute only works with units of pixels, i.e. this does not work

p = scatter(rand(1000), rand(1000);margin=3.0mm,title="A bunch of points", xlabel="x-value", ylabel="y-value",label="Some points",size=(100mm, 90mm))
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: MethodError: no method matching *(::Measures.Length{:mm,Float64}, ::Measures.Length{:mm,Float64})
Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...) at operators.jl:138
  *(::Measures.Length{:mm,Float64}, ::Measures.Length{:pct,T}) at /Users/roger/.julia/v0.5/Plots/src/layouts.jl:28
  *(::Measures.Measure, ::Number) at /Users/roger/.julia/v0.5/Measures/src/operations.jl:47
  ...
 in prepare_output(::Plots.Plot{Plots.GRBackend}) at /Users/roger/.julia/v0.5/Plots/src/plot.jl:235
 in display at /Users/roger/.julia/v0.5/Plots/src/output.jl:115 [inlined]
 in gui at /Users/roger/.julia/v0.5/Plots/src/output.jl:112 [inlined]
 in display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::MIME{Symbol("text/plain")}, ::Plots.Plot{Plots.GRBackend}) at /Users/roger/.julia/v0.5/Plots/src/output.jl:120
 in display(::Base.REPL.REPLDisplay{Base.REPL.LineEditREPL}, ::Plots.Plot{Plots.GRBackend}) at ./REPL.jl:135
 in display(::Plots.Plot{Plots.GRBackend}) at ./multimedia.jl:143
 in print_response(::Base.Terminals.TTYTerminal, ::Any, ::Void, ::Bool, ::Bool, ::Void) at ./REPL.jl:154
 in print_response(::Base.REPL.LineEditREPL, ::Any, ::Void, ::Bool, ::Bool) at ./REPL.jl:139
 in (::Base.REPL.##22#23{Bool,Base.REPL.##33#42{Base.REPL.LineEditREPL,Base.REPL.REPLHistoryProvider},Base.REPL.LineEditREPL,Base.LineEdit.Prompt})(::Base.LineEdit.MIState, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Bool) at ./REPL.jl:652
 in run_interface(::Base.Terminals.TTYTerminal, ::Base.LineEdit.ModalInterface) at ./LineEdit.jl:1579
 in run_interface(::Base.Terminals.TTYTerminal, ::Base.LineEdit.ModalInterface) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
 in run_frontend(::Base.REPL.LineEditREPL, ::Base.REPL.REPLBackendRef) at ./REPL.jl:903
 in run_repl(::Base.REPL.LineEditREPL, ::Base.##930#931) at ./REPL.jl:188
 in _start() at ./client.jl:360
 in _start() at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?

This would be useful especially when creating figures for publication, where one might want to display the figure exactly as it would be printed.
In Winston, the savefig function accepts optional width and height arguments, which can both be given as e.g. width = "100mm", and this would be a good alternative here, too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementimproving existing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions