JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.82k stars 348 forks source link

[BUG] aspect_ratio causes ylims() to have unexpected behaviour in REPL #3479

Open toma-vlad opened 3 years ago

toma-vlad commented 3 years ago

Details

First, I would like to mention, that I am relatively new to Julia and Plots, so maybe I am missing something.

If I run a file like this

using Plots 
x = [-1, -1,  1,  1]
y = [-1,  1, -1,  1]

try to scatter or plot and then check ylims(zm) I get one answer,

julia> zm = scatter(x,y, aspect_ratio = 1)

julia> xlims(zm)
(-1.590010487164327, 1.590010487164327)

which is also the correct one, if I savefig(zm, "case1.png"), more details further below. However, if I run it in one line, which I checked to be equivalent to having it inside the original file, then I get another answer.

julia> zm = scatter(x,y, aspect_ratio = 1); xlims(zm)
(-1.06, 1.06)

Additionally, I have checked the function Plots.axis_limits(zm.subplot[1], :x) and the same behaviour occurs.

The actual renders

  1. normal use

    zm = scatter(x,y, aspect_ratio = 1); savefig(zm, "case1.png")

    case1

  2. as expected, just calling the xlims() function doesn't affect the plot

    zm = scatter(x,y, aspect_ratio = 1); xlims(zm); savefig(zm, "case2.png")

    case2

  3. somebody could do this if they wanted to add something like a rectangle to the plot, but keep the original axis limits.

    zm = scatter(x,y, aspect_ratio = 1); scatter!(zm, xlims = xlims(zm)); savefig(zm, "case3.png")

    case3

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default) x
pyplot x
plotly x
plotlyjs x
pgfplotsx x
inspectdr x

Versions

Plots.jl version:

Status `/mnt/storage/vlad/.julia/environments/v1.6/Project.toml`
  [91a5bcdd] Plots v1.12.0

Backend version (]st -m):

Status /mnt/storage/vlad/.julia/environments/v1.6/Manifest.toml
  [621f4979] AbstractFFTs v1.0.1
  [1520ce14] AbstractTrees v0.3.4
  [79e6a3ab] Adapt v3.3.0
  [dce04be8] ArgCheck v2.1.0
  [ec485272] ArnoldiMethod v0.1.0
  [4fba245c] ArrayInterface v3.1.7
  [bf4720bc] AssetRegistry v0.1.0
  [c52e3926] Atom v0.12.31
  [13072b0f] AxisAlgorithms v1.0.0
  [198e06fe] BangBang v0.3.30
  [9718e550] Baselet v0.1.1
  [9e28174c] BinDeps v1.0.2
  [ad839575] Blink v0.12.5
  [00ebfdb7] CSTParser v2.5.0
  [49dc2e85] Calculus v0.5.1
  [324d7699] CategoricalArrays v0.9.6
  [d360d2e6] ChainRulesCore v0.9.39
  [b630d9fa] CheapThreads v0.2.3
  [53a63b46] CodeTools v0.7.1
  [da1fd8a2] CodeTracking v1.0.5
  [35d6a980] ColorSchemes v3.12.1
  [3da002f7] ColorTypes v0.10.12
  [5ae59095] Colors v0.12.8
  [861a8166] Combinatorics v1.0.2
  [a80b9123] CommonMark v0.6.4
  [38540f10] CommonSolve v0.2.0
  [bbf7d656] CommonSubexpressions v0.3.0
  [34da2185] Compat v3.27.0
  [a81c6b42] Compose v0.9.2
  [a33af91c] CompositionsBase v0.1.0
  [01234589] ConfigEnv v1.0.0
  [187b0558] ConstructionBase v1.1.0
  [d38c429a] Contour v0.5.7
  [150eb455] CoordinateTransformations v0.6.1
  [7ad07ef1] CoupledFields v0.2.0
  [a8cc5b0e] Crayons v4.0.4
  [9a962f9c] DataAPI v1.6.0
  [864edb3b] DataStructures v0.18.9
  [e2d170a0] DataValueInterfaces v1.0.0
  [3f0dd361] DefaultApplication v1.0.0
  [244e2a9f] DefineSingletons v0.1.1
  [2b5f629d] DiffEqBase v6.60.0
  [163ba53b] DiffResults v1.0.3
  [b552c78f] DiffRules v1.0.2
  [b4f34e82] Distances v0.10.2
  [31c24e10] Distributions v0.24.18
  [33d173f1] DocSeeker v0.4.3
  [ffbed154] DocStringExtensions v0.8.4
  [e30172f5] Documenter v0.26.3
  [fa6b7ba4] DualNumbers v0.6.5
  [d4d017d3] ExponentialUtilities v1.8.4
  [c87230d0] FFMPEG v0.4.0
  [7a1cc6ca] FFTW v1.4.0
  [9aa1b823] FastClosures v0.3.2
  [5789e2e9] FileIO v1.8.0
  [1a297f60] FillArrays v0.11.7
  [6a86dc24] FiniteDiff v2.8.0
  [53c48c17] FixedPointNumbers v0.8.4
  [08572546] FlameGraphs v0.2.5
  [59287772] Formatting v0.4.2
  [f6369f11] ForwardDiff v0.10.18
  [069b7b12] FunctionWrappers v1.1.2
  [de31a74c] FunctionalCollections v0.5.0
  [fb4132e2] FuzzyCompletions v0.4.1
  [28b8d3ca] GR v0.57.4
  [c91e804a] Gadfly v1.3.2
  [5c1252a2] GeometryBasics v0.3.12
  [42e2da0e] Grisu v1.0.0
  [19dc6840] HCubature v1.5.0
  [cd3eb016] HTTP v0.8.19
  [a1b4810d] Hexagons v0.2.0
  [9fb69e20] Hiccup v0.2.2
  [0e44f5e4] Hwloc v1.3.0
  [34004b35] HypergeometricFunctions v0.3.5
  [b5f81e59] IOCapture v0.1.1
  [615f187c] IfElse v0.1.0
  [9b13fd28] IndirectArrays v0.5.1
  [d25df0c9] Inflate v0.1.2
  [83e8ac13] IniFile v0.5.0
  [22cec73e] InitialValues v0.2.10
  [a98d9a8b] Interpolations v0.13.2
  [c8e1da08] IterTools v1.3.0
  [42fd0dbc] IterativeSolvers v0.9.0
  [82899510] IteratorInterfaceExtensions v1.0.0
  [692b3bcd] JLLWrappers v1.3.0
  [97c1335a] JSExpr v0.5.2
  [682c06a0] JSON v0.21.1
  [0f8b85d8] JSON3 v1.8.1
  [98e50ef6] JuliaFormatter v0.12.3
  [aa1ae85d] JuliaInterpreter v0.8.14
  [e5e0dc1b] Juno v0.8.4
  [5ab0869b] KernelDensity v0.6.2
  [7c4cb9fa] LNR v0.2.1
  [b964fa9f] LaTeXStrings v1.2.1
  [2ee39098] LabelledArrays v1.6.0
  [e07c0bfa] LaserTypes v0.1.4 /mnt/storage/vlad/.julia/dev/LaserTypes
  [23fbe1c1] Latexify v0.15.5
  [50d2b5c4] Lazy v0.15.1
  [1d6d02ad] LeftChildRightSiblingTrees v0.1.2
  [093fc24a] LightGraphs v1.3.5
  [d3d80556] LineSearches v7.1.1
  [4345ca2d] Loess v0.5.3
  [2ab3a3ac] LogExpFunctions v0.2.3
  [bdcacae8] LoopVectorization v0.12.12
  [1914dd2f] MacroTools v0.5.6
  [739be429] MbedTLS v1.0.3
  [eff96d63] Measurements v2.6.0
  [442fdcdd] Measures v0.3.1
  [e89f7d12] Media v0.5.0
  [128add7d] MicroCollections v0.1.0
  [e1d29d7a] Missings v1.0.0
  [46d2c3a1] MuladdMacro v0.2.2
  [ffc61752] Mustache v1.0.10
  [a975b10e] Mux v0.7.5
  [d41bc354] NLSolversBase v7.8.0
  [2774e3e8] NLsolve v4.5.1
  [77ba4419] NaNMath v0.3.5
  [8913a72c] NonlinearSolve v0.3.8
  [510215fc] Observables v0.3.3
  [6fe1bfb0] OffsetArrays v1.7.0
  [bac558e1] OrderedCollections v1.4.0
  [1dea7af3] OrdinaryDiffEq v5.52.4
  [90014a1f] PDMats v0.11.0
  [8314cec4] PGFPlotsX v1.2.10
  [d96e819e] Parameters v0.12.2
  [69de0a69] Parsers v1.1.0
  [5ad8b20f] PhysicalConstants v0.2.1
  [fa939f87] Pidfile v1.2.0
  [ccf2f8ad] PlotThemes v2.0.1
  [995b91a9] PlotUtils v1.0.10
  [58dd65bb] Plotly v0.3.0
  [a03496cd] PlotlyBase v0.5.2
  [f0f68f2c] PlotlyJS v0.14.1
  [91a5bcdd] Plots v1.12.0
  [21216c6a] Preferences v1.2.1
  [1fd47b50] QuadGK v2.4.1
  [c84ed2f1] Ratios v0.4.0
  [3cdcf5f2] RecipesBase v1.1.1
  [01d81517] RecipesPipeline v0.3.2
  [731186ca] RecursiveArrayTools v2.11.3
  [f2c3362d] RecursiveFactorization v0.1.12
  [189a3867] Reexport v0.2.0
  [42d2dcc6] Referenceables v0.1.2
  [ae029012] Requires v1.1.3
  [79098fc4] Rmath v0.7.0
  [f2b01f46] Roots v1.0.9
  [476501e8] SLEEFPirates v0.6.15
  [0bca4576] SciMLBase v1.13.0
  [6c6a2e73] Scratch v1.0.3
  [efcf1570] Setfield v0.7.0
  [992d4aef] Showoff v0.3.2
  [699a6c99] SimpleTraits v0.9.3
  [a2af1166] SortingAlgorithms v0.3.1
  [47a9eef4] SparseDiffTools v1.13.2
  [276daf66] SpecialFunctions v1.3.0
  [171d559e] SplittablesBase v0.1.13
  [aedffcd0] Static v0.2.4
  [90137ffa] StaticArrays v1.1.1
  [2913bbd2] StatsBase v0.33.6
  [4c63d2b9] StatsFuns v0.9.8
  [7792a7ef] StrideArraysCore v0.1.5
  [88034a9c] StringDistances v0.10.0
  [09ab397b] StructArrays v0.5.1
  [856f2bd8] StructTypes v1.7.2
  [3783bdb8] TableTraits v1.0.1
  [bd369af6] Tables v1.4.2
  [1da6f4ae] Telegram v1.1.0
  [8290d209] ThreadingUtilities v0.4.1
  [ac1d9e8a] ThreadsX v0.1.7
  [0796e94c] Tokenize v0.5.16
  [28d57a85] Transducers v0.4.64
  [a2a6695c] TreeViews v0.3.0
  [30578b45] URIParser v0.4.1
  [3a884ed6] UnPack v1.0.2
  [1986cc42] Unitful v1.7.0
  [a7773ee8] UnitfulAtomic v1.0.0
  [3d5dd08c] VectorizationBase v0.19.31
  [19fa3120] VertexSafeGraphs v0.1.2
  [0f1e0344] WebIO v0.8.15
  [104b5d7c] WebSockets v1.5.9
  [cc8bc4a8] Widgets v0.6.2
  [efce3f68] WoodburyMatrices v0.5.3
  [700de1a5] ZygoteRules v0.2.1
  [6e34b625] Bzip2_jll v1.0.6+5
  [83423d85] Cairo_jll v1.16.0+6
  [5ae413db] EarCut_jll v2.1.5+1
  [2e619515] Expat_jll v2.2.7+6
  [b22a6f82] FFMPEG_jll v4.3.1+4
  [f5851436] FFTW_jll v3.3.9+7
  [a3f928ae] Fontconfig_jll v2.13.1+14
  [d7e528f0] FreeType2_jll v2.10.1+5
  [559328eb] FriBidi_jll v1.0.5+6
  [0656b61e] GLFW_jll v3.3.3+0
  [d2c73de3] GR_jll v0.57.2+0
  [78b55507] Gettext_jll v0.20.1+7
  [7746bdde] Glib_jll v2.59.0+4
  [e33a78d0] Hwloc_jll v2.4.1+0
  [1d5cc7b8] IntelOpenMP_jll v2018.0.3+2
  [aacddb02] JpegTurbo_jll v2.0.1+3
  [f7e6163d] Kaleido_jll v0.1.0+0
  [c1c5ebd0] LAME_jll v3.100.0+3
  [dd4b983a] LZO_jll v2.10.0+3
  [dd192d2f] LibVPX_jll v1.9.0+1
  [e9f186c6] Libffi_jll v3.2.1+4
  [d4300ac3] Libgcrypt_jll v1.8.5+4
  [7e76a0d4] Libglvnd_jll v1.3.0+3
  [7add5ba3] Libgpg_error_jll v1.36.0+3
  [94ce4f54] Libiconv_jll v1.16.0+7
  [4b2f31a3] Libmount_jll v2.34.0+3
  [89763e89] Libtiff_jll v4.1.0+2
  [38a345b3] Libuuid_jll v2.34.0+7
  [856f044c] MKL_jll v2021.1.1+1
  [e7412a2a] Ogg_jll v1.3.4+2
  [458c3c95] OpenSSL_jll v1.1.1+6
  [efe28fd5] OpenSpecFun_jll v0.5.4+0
  [91d4177d] Opus_jll v1.3.1+3
  [2f80f16e] PCRE_jll v8.42.0+4
  [30392449] Pixman_jll v0.40.0+0
  [ea2cea3b] Qt5Base_jll v5.15.2+0
  [f50d1b31] Rmath_jll v0.3.0+0
  [a2964d1f] Wayland_jll v1.17.0+4
  [2381bf8a] Wayland_protocols_jll v1.18.0+4
  [02c8fc9c] XML2_jll v2.9.11+0
  [aed1982a] XSLT_jll v1.1.33+4
  [4f6342f7] Xorg_libX11_jll v1.6.9+4
  [0c0b7dd1] Xorg_libXau_jll v1.0.9+4
  [935fb764] Xorg_libXcursor_jll v1.2.0+4
  [a3789734] Xorg_libXdmcp_jll v1.1.3+4
  [1082639a] Xorg_libXext_jll v1.3.4+4
  [d091e8ba] Xorg_libXfixes_jll v5.0.3+4
  [a51aa0fd] Xorg_libXi_jll v1.7.10+4
  [d1454406] Xorg_libXinerama_jll v1.1.4+4
  [ec84b674] Xorg_libXrandr_jll v1.5.2+4
  [ea2f1a96] Xorg_libXrender_jll v0.9.10+4
  [14d82f49] Xorg_libpthread_stubs_jll v0.1.0+3
  [c7cfdc94] Xorg_libxcb_jll v1.13.0+3
  [cc61e674] Xorg_libxkbfile_jll v1.1.0+4
  [12413925] Xorg_xcb_util_image_jll v0.4.0+1
  [2def613f] Xorg_xcb_util_jll v0.4.0+1
  [975044d2] Xorg_xcb_util_keysyms_jll v0.4.0+1
  [0d47668e] Xorg_xcb_util_renderutil_jll v0.3.9+1
  [c22f9ab0] Xorg_xcb_util_wm_jll v0.4.1+1
  [35661453] Xorg_xkbcomp_jll v1.4.2+4
  [33bec58e] Xorg_xkeyboard_config_jll v2.27.0+4
  [c5fb5394] Xorg_xtrans_jll v1.4.0+3
  [3161d3a3] Zstd_jll v1.4.8+0
  [0ac62f75] libass_jll v0.14.0+4
  [f638f0a6] libfdk_aac_jll v0.1.6+4
  [b53b4c65] libpng_jll v1.6.37+6
  [f27f6e37] libvorbis_jll v1.3.6+6
  [1270edf5] x264_jll v2020.7.14+2
  [dfaa095f] x265_jll v3.0.0+3
  [d8fb68d0] xkbcommon_jll v0.9.1+5
  [0dad84c5] ArgTools
  [56f22d72] Artifacts
  [2a0f44e3] Base64
  [ade2ca70] Dates
  [8bb1440f] DelimitedFiles
  [8ba89e20] Distributed
  [f43a241f] Downloads
  [7b1f6079] FileWatching
  [9fa8497b] Future
  [b77e0a4c] InteractiveUtils
  [4af54fe1] LazyArtifacts
  [b27032c2] LibCURL
  [76f85450] LibGit2
  [8f399da3] Libdl
  [37e2e46d] LinearAlgebra
  [56ddb016] Logging
  [d6f4376e] Markdown
  [a63ad114] Mmap
  [ca575930] NetworkOptions
  [44cfe95a] Pkg
  [de0858da] Printf
  [9abbd945] Profile
  [3fa0cd96] REPL
  [9a3f8284] Random
  [ea8e919c] SHA
  [9e88b42a] Serialization
  [1a1011a3] SharedArrays
  [6462fe0b] Sockets
  [2f01184e] SparseArrays
  [10745b16] Statistics
  [4607b0f0] SuiteSparse
  [fa267f1f] TOML
  [a4e569a6] Tar
  [8dfed614] Test
  [cf7118a7] UUIDs
  [4ec0a83e] Unicode
  [e66e0078] CompilerSupportLibraries_jll
  [deac9b47] LibCURL_jll
  [29816b5a] LibSSH2_jll
  [c8ffd9c3] MbedTLS_jll
  [14a3606d] MozillaCACerts_jll
  [83775a58] Zlib_jll
  [8e850ede] nghttp2_jll
  [3f19e933] p7zip_jll

Output of versioninfo():


Julia Version 1.6.0
Commit f9720dc2eb (2021-03-24 12:55 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2640 v4 @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, broadwell)
Environment:
  JULIA_DEPOT_PATH = /mnt/storage/vlad/.julia
  JULIA_EDITOR = "/home/vlad/.vscode-server/bin/cfa2e218100323074ac1948c885448fdf4de2a7f/node"
  JULIA_GPG = 3673DF529D9049477F76B37566E3C7DC03D6E495
  JULIA_NUM_THREADS = 20
  JULIA_PATH = /usr/local/julia
  JULIA_VERSION = 1.6.0```
toma-vlad commented 3 years ago

I have also tested

zm = scatter(x,y, label = false, framestyle = :box, ann = [(:tr, "corner")])

a_r_vs_ann1 vs

zm = scatter(x,y, label = false, aspect_ratio = 1, framestyle = :box, ann = [(:tr, "corner")])

a_r_vs_ann2

and in the 2nd case the annotation seems to behave as though the corner is placed where it would be if the axis were equal.

t-bltg commented 3 years ago

Related: https://github.com/JuliaPlots/Plots.jl/issues/3633