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

shared legend for subplots on some backends #673

Open
tpapp opened this issue Feb 8, 2017 · 11 comments
Open

shared legend for subplots on some backends #673

tpapp opened this issue Feb 8, 2017 · 11 comments

Comments

@tpapp
Copy link

tpapp commented Feb 8, 2017

On some backends (plotly,plotlyjs), the following code combines the legends into a single one, while on some backends the (gr, pyplot) the legends are separate for each subplot (as they should be). Cf discussion on Discourse. Same with master and release versions (at the time of opening the issue).

using DataFrames
using Plots
using StatPlots

plotly()

data = let years=[], spelltypes=[], values=[]
    for year in 1980:2000
        for spelltype in 1:30
            push!(values, spelltype+(rand()-0.5)/10)
            push!(years, year)
            push!(spelltypes, spelltype)
        end
    end
    DataFrame(year=years, spelltype=spelltypes, value=values)
end

pick(data, range) = data[[spelltype  range for spelltype in data[:spelltype]],:]
subplot(data, range) = plot(pick(data, range), :year, :value, group=:spelltype)

p1 = subplot(data, 1:10)
p2 = subplot(data, 11:20)
p3 = subplot(data, 21:30)
plot(p1, p2, p3)         # would like separate legend for each subplot
@Nosferican
Copy link

Nosferican commented Apr 18, 2018

I think the placement of legends in combined plots is sub-optimal right now. Using :bottom, :right, :top, and others produce weird output at least with gr. It would be nice to allow a :shared keyword or something to combine the legend as well.

@davidzentlermunro
Copy link

I second Nosferican's suggestion for a :shared keyword

@mkborregaard
Copy link
Member

yes it would be nice to have for sure

@davidzentlermunro
Copy link

In the absence of that, any suggestions for how I would get it using pyplot() backend?

@mkborregaard
Copy link
Member

I think the placement of legends in combined plots is sub-optimal right now

You can also pass an (x,y) Tuple for fine-grained control.

@davidzentlermunro
Copy link

true, but I can't (easily) get the legend outside of a subplot right? So for example I've got a 6 by 2 layout and would ideally have the legend sitting centred above the top row of plots.

@mkborregaard
Copy link
Member

mkborregaard commented Jan 30, 2019

Colorbar or legend? There are some hacks - with colorbar you can set the clims then optionally use the @layout macro to align widths:

a,b,c,d = ntuple(x->randn(10000), 4)
p1 = histogram2d(a,b, colorbar = false)
p2 = histogram2d(c,d, clims = zlims(p1))
plot(p1, p2, layout = @layout([a{0.46w} b]))

skaermbillede 2019-01-30 kl 14 33 49

With legend you can always use an invisible subplot and hack it a bit:

plot(
           scatter(rand(100,3), legend = false),
               scatter(rand(100,3), legend = false),
                   scatter((1:3)', xlim = (4,5), legend = true, framestyle = :none),
                   layout = @layout([a b c{0.1w}]))

skaermbillede 2019-01-30 kl 14 43 09

@mkborregaard
Copy link
Member

But actually, improvements to the general legend capability are much in demand

@mkborregaard mkborregaard mentioned this issue Feb 29, 2020
16 tasks
@truedichotomy
Copy link

I'm encountering this legend issue with my multi-panel plot (some of the subplots are heatmaps) using Plotly as my backend. A coherent solution to this problem allowing for separate legends for each subplot is very appreciated.

@isentropic
Copy link
Member

This is a longstanding issue with plotly, and it is really due to plotlys inability to have multiple legends.

@fbanning
Copy link

I would also like to have the option to display just one legend for all subplots on GR backend. I would like to use a separate keyword plot_legend instead of legend for that, which is logically similar to how plot_title and title should behave (although plot_title is not implemented currently).

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

8 participants