Plots.jl: Colorbars inside plot areas

Created on 25 Jul 2016  Â·  5Comments  Â·  Source: JuliaPlots/Plots.jl

When I run the following code...

using Plots
y = cumsum(randn(100,3))
scatter(y, zcolor=y)

...I see a colorbar for the first series outside the plot area, and two colorbars for the other two series superimposed inside the plot area:
colorbar1
I was expecting the three series to share a single colorbar placed outside the plot area. Thinking I could keep the first series's colorbar on and disable the others, I added colorbar=[true false false], but the plot output did not change.

When I add layout=2, the first two colorbars are placed outside the two plot areas, and the third is superimposed on the second plot area:

scatter(y, zcolor=y, layout=2)

colorbar2

What is the syntax for having multiple series share one colorbar?

EDIT: I'm using the PyPlot backend with Plots 0.8.1. When I switch to GR, there is one colorbar located outside the plot area.

PyPlot

Most helpful comment

Closing with #1084

All 5 comments

This specific behavior is specific to pyplot, and I think I see what is happening. Each series overwrites the saved colorbar handle with a new colorbar, and only the last one in each subplot is getting positioned properly.

Note to self: when fixing, do a search for cbar_ax, and check that the field exists before adding a new one.

As a work around I used something along the lines:

h1 = contour(rand(3,3), cbar=false, clims=(0,3), fill=true)
scatter!(1:3,1:3, zcolor=1:3, cbar=false, clims=(0,3))
h2 = scatter([0,0], [0,1], zcolor=[0,3], clims=(0,3),
             xlims=(1,1.1), axis=false, label="", colorbar_title="cbar", grid=false)
l = @layout [grid(1,1) a{0.01w}]
plot(h1,h2,layout=l)

Excellent hack. You've figured me out... Write ugly hacks so I'm compelled
to fix the underlying problem!

On Tuesday, September 27, 2016, Mauro [email protected] wrote:

As a work around I used something along the lines:

h1 = contour(rand(3,3), cbar=false, clims=(0,3), fill=true)
scatter!(1:3,1:3, zcolor=1:3, cbar=false, clims=(0,3))
h2 = scatter([0,0], [0,1], zcolor=[0,3], clims=(0,3),
xlims=(1,1.1), axis=false, label="", colorbar_title="cbar")
l = @layout [grid(1,1) a{0.01w}]
plot(h1,h2,layout=l)

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/tbreloff/Plots.jl/issues/412#issuecomment-249813635,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA492vorMk_JxQi140SfzaQfB4ioKfKsks5quOGDgaJpZM4JUjWQ
.

I'll start trolling all of your issues which are open longer than one week with dirty hacks. That will teach you! ;-)

(No, seriously, thanks for all your good and hard work on Plots.jl!)

Closing with #1084

Was this page helpful?
0 / 5 - 0 ratings

Related issues

crstnbr picture crstnbr  Â·  3Comments

Cody-G picture Cody-G  Â·  3Comments

asinghvi17 picture asinghvi17  Â·  3Comments

ereday picture ereday  Â·  3Comments

apalugniok picture apalugniok  Â·  3Comments