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

aspect_ratio not working expectedly with PGFPlotsX #4766

Open
jywu20 opened this issue Jun 8, 2023 · 3 comments
Open

aspect_ratio not working expectedly with PGFPlotsX #4766

jywu20 opened this issue Jun 8, 2023 · 3 comments

Comments

@jywu20
Copy link

jywu20 commented Jun 8, 2023

Details

When plotting heatmap with PGFPlotsX backend, I want to have aspect_ratio = 1. The following script

using Plots
pgfplotsx()

heatmap([1, 2, 3, 4], [1, 2, 3, 4], [1 2 1 0 ; 1  3 4 5; 1 0 0 1; 1 9 0 8], aspect_ratio = :equal)  

gives the following figure:
1
The x axis of this plot is of course too wide; but then, the following script aimed to solve the problem by fixing the x range eliminates the effect of aspect_ratio = :equal:

using Plots
pgfplotsx()

heatmap([1, 2, 3, 4], [1, 2, 3, 4], [1 2 1 0 ; 1  3 4 5; 1 0 0 1; 1 9 0 8], 
aspect_ratio = :equal, xlim=(0.5, 4.5))
2

By inspecting the LaTeX code generated, the problem seems to be that heatmap, when asked to generate a figure with aspect_ratio = :equal, simply adjusts the scale of the x axis so that the main body of the heatmap becomes a square; but this is not what is intuitively expected: there is an axis equal image option for the axis environment in tikz, and, IMHO, this is what should be invoked when the aspect_ratio = :equal option is used.

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default)
pythonplot
plotlyjs
pgfplotsx x
unicodeplots
inspectdr
gaston

Versions

Plots.jl version: [91a5bcdd] Plots v1.36.1
Backend version (]st -m <backend(s)>): [8314cec4] PGFPlotsX v1.5.1
Output of versioninfo():

Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, tigerlake)
@jywu20 jywu20 added the bug label Jun 8, 2023
@BeastyBlacksmith
Copy link
Member

You can use that via

heatmap([1, 2, 3, 4], [1, 2, 3, 4], [1 2 1 0 ; 1  3 4 5; 1 0 0 1; 1 9 0 8], 
       axis_equal_image = true, xlim=(0.5, 4.5), extra_kwargs = :subplot)

but note, that this will create a figure of a different size.

@jywu20
Copy link
Author

jywu20 commented Jun 12, 2023

I tried this and it seems for PGFPlotsX, it still doesn't work. The problem seems to be that the option axis_equal_image is added to the \addplot3 command in the generated LaTeX code, not the expected axis environment.

@BeastyBlacksmith
Copy link
Member

I guess you missed the extra_kwargs = :subplot part?

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

No branches or pull requests

2 participants