Skip to content

Horizontal Legend below the chart #53

Description

@prog8

I couldn't find any way to configure legend to be placed under the chart in a single line. It would be nice if Plotly makes it possible to move the legend below the chart.

Activity

  1. etpinard commented on Dec 1, 2015

    @etpinard
    Contributor

    @prog8 correct. plotly.js legends don't offer much in terms of customization.

    You can move the legend using layout.legend.x and layout.legend.y, but there's no way to place the items horizontally at the moment.

  2. prog8 commented on Dec 1, 2015

    @prog8
    Author

    Is it planned to make legends more customizable in nearest future? If yes do you know any estimates?

  3. czellweg commented on Dec 2, 2015

    @czellweg

    For anybody wanting to place the legend under the chart, one way to achieve this would be like so:

    layout: {
    ....
      legend:{
        xanchor:"center",
        yanchor:"top",
        y:-0.3, // play with it
        x:0.5   // play with it
      }
    }
    

    You can also check out the effects of the x/yanchor and x/y values on https://plot.ly/plot: plot a graph, then change Layout -> Horz Position, Vert Position, Horz anchor, Vert anchor.

  4. prog8 commented on Dec 2, 2015

    @prog8
    Author

    Yes but this doesn't change the legend layout. Legend entries are always one below another. They are never in the same line.

  5. n-riesco commented on Apr 26, 2016

    @n-riesco
    Contributor

    @etpinard @mdtusz I'm thinking of the following API for this feature:

    layout: {
        legend : {
            orientation: 'horizontal' | 'vertical'
        }
    }
    
  6. etpinard commented on Apr 26, 2016

    @etpinard
    Contributor

    @n-riesco I'd vote for

    layout: {
        legend : {
            orientation: 'h' | 'v'
        }
    }

    similar to bar orientation.

  7. mdtusz commented on Apr 26, 2016

    @mdtusz
    Contributor

    ⬆️ agreed, but only for the sake of consistency with the existing style.

  8. added a commit that references this issue on May 17, 2016
    5c91b8f
  9. ptoche commented on Sep 15, 2018

    @ptoche

    I came here after receiving the following message:

    Warning message:
    plotly.js does not (yet) support horizontal legend items 
    You can track progress here: 
    https://github.com/plotly/plotly.js/issues/53
    

    I do not usually receive this warning message. In a ggplot2 object processed by plotly I set guides(colour = guide_legend(ncol=1)), clearly requesting a vertical legend (not a single-line horizontal legend), which works as expected. I came to this issue as directed by the warning message and see this issue is now closed: Is this warning still relevant? Thanks.

  10. alexcjohnson commented on Sep 15, 2018

    @alexcjohnson
    Collaborator
  11. mikkokotila commented on Jan 12, 2019

    @mikkokotila

    Is there any update on this?

    EDITED: Amazing. It's working as per the above format.

  12. marwin1991 commented on Jan 12, 2019

    @marwin1991

    image

    legend is coverd by x-axies label

  13. mikkokotila commented on Jan 12, 2019

    @mikkokotila

    @marwin1991 Try something like this > {legend: {x: 0.35, y: 5, orientation: 'h'},

  14. marwin1991 commented on Jan 12, 2019

    @marwin1991
                        legend : {
                            orientation: 'h',
                            y:-0.15
                        },
    

    this helps

  15. usser123 commented on Apr 23, 2020

    @usser123

    Horizontal legend is not working for me. Is this a bug ?

  16. MikkoHaavisto commented on Apr 3, 2021

    @MikkoHaavisto

    When I set the legend to 'h', but it only moves the legend title to the side, the variable legends are still vertically aligned. I couldn't get one below the other.

    Is this feature working for someone?

  17. nicolaskruchten commented on Apr 4, 2021

    @nicolaskruchten
    Contributor

    Yes, this works for me: https://codepen.io/nicolaskruchten/pen/JjENwZZ?editors=0010 ... it looks like this:

    newplot

  18. added a commit that references this issue on Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions