How to get equally scaled axes with Plots in Julia
Asked Answered
P

2

7

I have created a heatmap plot using in Julia by using the Plotly with the Plots package. I generate the heatmap with the following command heatmap(10^9 .* (height + deformation)). Then, I get a plot that looks like this heatmap

The length of the x-axis and y-axis both range from 0 to 256, but nonetheless they do not have the same scale as seen from the rectangular shape of the heatmap. How can I make the scale of the x-axis and y-axis equal?

Palaeontology answered 18/4, 2019 at 20:36 Comment(0)
T
9

You can use aspect_ratio attribute with :equal option.

heatmap(10^9 .* (height + deformation), aspect_ratio=:equal)

should give you equally scaled x and y axes. If you give a number instead of :equal, plot area is resized so that 1 y-unit is the same size as aspect_ratio x-units.

You can see other attributes to use with Plots.jl in the relevant section of Plots.jl documentation.

Tachometer answered 18/4, 2019 at 20:50 Comment(0)
C
1

This does not seem to work on my setup. Plots v1.39.0 PlotlyJS v0.18.12

using Plots
plotly()  
xs = [1,2,3, 4]  
ys = [10,20,30, 40]  
scatter(xs, ys, aspect_ratio=1)  

I can pass any number as well as :equal to the aspect_ratio argument without any affect on the plot..

The only thing that seems to work for my setup is manually setting the plot size with plotly(size=(x_size,y_size)) and manually setting xlim and ylim, but that sucks a little.

Convex answered 22/2 at 8:40 Comment(1)
update, for a while during testing using aspect_ratio=1 worked, and now it stopped working again...Convex

© 2022 - 2024 — McMap. All rights reserved.