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] Colorbar doesn’t reflect ColorGradient scale as specified in cgrad(…, scale = ) -works on gr #3420

Closed
casasgomezuribarri opened this issue Apr 5, 2021 · 5 comments

Comments

@casasgomezuribarri
Copy link

Details

I have built the following composite plot:

# Data
x = rand([1, 2, 3, 4, 5], 50)
y = rand(50)
z = rand(50)

# Vector with labels to show on hover
hovector = []
for i in 1:length(x)
    label = "$(x[i]), $(y[i]), $(z[i])"
    push!(hovector, label)
 end

# Frequency histograms and blank plot for top right corner
plotly()
x_hist = Plots.plot(x,
    st = :histogram,
    nb = 50,
    leg = false,
    yguide = "Frequency",
    xticks = false,
    guide_position = :left,
    color = RGB{Float64}(0.031,0.318,0.612))
y_hist = Plots.plot(y,
    st = :histogram,
    nb = 50,
    leg = false,
    color = RGB{Float64}(0.031,0.318,0.612),
    yticks = false,
    xguide = "Frequency",
    orientation = :h)
blank = Plots.plot(grid = false, showaxis = false)

# Main plot
bubblecolor = cgrad(:inferno, scale = :exp)
bubbles = Plots.plot(x, y, st = :scatter,     
    marker_z = z,
    ms = 10,
    hover = hovector,
    color = bubblecolor, 
    label = nothing,
    cb = false)

# Workaround for title (plot_title not currently implemented, see http://docs.juliaplots.org/latest/generated/attributes_plot/)
title = Plots.plot(ones(3), line = nothing, size = (600, 80),
    grid = false, showaxis = false, leg = false,
    annotations=(2, 1.5, "Main Title"))

# Merge plots
l = @layout [x_hist              blank
            bubbles{0.8w,0.8h}   y_hist]
plots = Plots.plot(x_hist, blank, bubbles, y_hist, 
        layout = l, link = :both,
        size = (700, 500))
superplot = Plots.plot(title, plots, layout = grid(2,1,heights=[0.1,0.9]))

# Add colorbar
Plots.plot!([0], [0], zcolor=[NaN], cbtitle="Intensity", leg = false,
        clims = extrema(z),
        color = bubblecolor,
        background_color_subplot=:transparent,
        markerstrokecolor=:transparent, framestyle=:none, 
        cb = :right,
        inset=bbox(0.1, 0, 0.05, 0.9, :center, :right), 
        subplot=6)

which gives me:

image

My question is related to the last block # Add colorbar (note the color gradient bubblecolor defined just under # Main plot). I am using an exponential scale for my color gradient to make lower Intensity values stand out more clearly -darkly-, and although this is reflected in the color of the bubbles themselves, the colorbar still shows the default linear scale of the :inferno color gradient. This obviously affects the readability of the main scatter.

If I change the line where bubblecolor is defined to

bubblecolor = cgrad(:inferno, rev = true, scale = :exp)

then I get:

image

So, the color attribute in the last block is sensitive to changes in rev within cgrad, but not scale. Is this an expected limitation, or am I doing something wrong?

PS: Any idea why the cbtitle “Intensity” doesn’t show up? This is less of an issue but would be great to be able to include it.

Backends

This bug occurs on ( insert x below )

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

Versions

Plots.jl version:
Backend version (]st -m):
Output of versioninfo():

@hervasa2
Copy link

hervasa2 commented Jun 9, 2021

I have also found this same bug. The colorbar in pyplot() does not respect the cgrad scale. This however works in gr().
This used to work in v1.10.2. I noticed the bug once I upgraded to v1.16.4.
An example follows:
pyplot()
A = rand(0:10,10,10)
grad = cgrad(:inferno, scale =:log)
heatmap(A, c = grad)
Screen Shot 2021-06-09 at 8 18 51 PM
grad2 = cgrad(:inferno, scale =:exp)
heatmap(A, c = grad2)
Screen Shot 2021-06-09 at 8 19 09 PM

And now in gr()
gr()
heatmap(A, c = grad)
Screen Shot 2021-06-09 at 8 22 14 PM
heatmap(A, c = grad2)
Screen Shot 2021-06-09 at 8 22 22 PM

@fhagemann
Copy link
Contributor

This bug was introduced from v1.10.5 to v1.10.6, so I guess that its source is either commit d59f6c9 or commit 100da5c.

I hope that this is useful for someone. I'm lacking the experience to judge which line might be the source of the problem...

@schustermartin
Copy link

I encountered this as well!

@isentropic
Copy link
Member

I'm aware of the logscale problem, though I need help.
#3432

@isentropic
Copy link
Member

let's focus on this in #3174

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

6 participants