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

[BUG] heatmap output shifts relative to axis when using logarithmic xscale and setting xlims on GR #4908

Open
LordCMonkey opened this issue Mar 20, 2024 · 1 comment
Labels

Comments

@LordCMonkey
Copy link

Details

When plotting with heatmap(x, y, z::matrix) and a logarithmic xscale, setting xlims causes the heatmap output to shift to an incorrect position on the x axis.
The same happens when first plotting using heatmap(x, y, z::matrix) and then plotting 2D data, even without explicitly setting xlims, The 2D data is plotted in the correct location.
This also occurs when using :ln or :log2 and scatter instead of plot.

The expected output can be observed when using plotly or pyplot (for :log10).

Minimal working example:

using Plots

function test_bug()
    x = [10.0^x for x in 0:1]
    A = zeros(2, 2)

    heatmap(x, 1:2, A, xscale=:log10,
            xlims=[10.0^-1, 10.0^2]
    )
    #plot!(x, x -> 1.8, label="")
end

function demonstrate()
    gr()
    gui(test_bug())
    
    plotly()
    gui(test_bug())
    
    pyplot()
    gui(test_bug())
end

When commenting the xlims=.. line and uncommenting the plot! call, the same behaviour occurs.

Backends

This bug occurs on ( insert x below )

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

Versions

Plots.jl version: 1.40.2
Backend version: GR: 0.73.3, PlotlyBase 0.8.19 & PlotlyKaleide 2.2.4, PyPlot 2.11.2
Output of versioninfo():

Julia Version 1.10.2
Commit bd47eca2c8 (2024-03-01 10:14 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 4 × Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 4 default, 0 interactive, 2 GC (on 4 virtual cores)
Environment:
JULIA_NUM_THREADS = auto

@ktitimbo
Copy link

ktitimbo commented Apr 12, 2024

This is still an issue

Plots v1.40.4
GR v0.72.8

I adapted an example from here, and I now get

x = collect(LinRange(0.001,4,1001))
y = 1:10
z = exp.(-x) * y'
xlog10 = log10.(x)

plot(
    heatmap(x, y, z, xscale = :log10, title = "Ideal", color=:plasma),
    heatmap(xlog10, y, z, xformatter = xx -> "10^{$(Int(xx))}", title = "Non-ideal", color=:plasma)
)

image

The "ideal" construction doesn't produce the right output

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

No branches or pull requests

2 participants