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

Stacked binary traces #5274

Closed
ciuliene opened this issue Nov 13, 2020 · 4 comments
Closed

Stacked binary traces #5274

ciuliene opened this issue Nov 13, 2020 · 4 comments
Labels
bug something broken

Comments

@ciuliene
Copy link

Hello, I have a problem with Plotly.js. I'm trying to draw some traces which have 0 and 1 as values. They are digital variables and what I want to do is to draw them one above the other one, like this:

Schermata 2020-11-13 alle 22 15 25

To do so, I faked each trace values. First trace can be 0 or 1, second trace can be 3 or 4, third trace can be 6 or 7, etc...
The problem is when I remove a trace using the legend. The result is something like this:
Schermata 2020-11-13 alle 22 17 18

I'd like to have the other lines to be redrawn without the removed one.

So, the question is: is there an easier way to do this? Something like "stacked binary layout"?

Thank you!

@alexcjohnson
Copy link
Collaborator

alexcjohnson commented Nov 13, 2020

You can use a category axis. Might just work exactly as you have it but with yaxis.type='category', but then you don't need to encode the values as numbers, any unique values will do. Here I just used strings to get a category axis automatically:

Plotly.newPlot(gd,
    [{y: ['a','b']},{y:['c','d']},{y:['e','f']}],
    {yaxis:{tickvals:['a','b','c','d','e','f'],ticktext:['OFF','ON     ','OFF','ON     ','OFF','ON     ']}}
)

Screen Shot 2020-11-13 at 5 11 18 PM

That said @archmoj I think there's a bug here when I try to include categoryorder, which is necessary to ensure the Off values always come before the On values: Then when I hide a trace via the legend, its categories are still there:

Plotly.newPlot(gd,
    [{y: ['b','a']},{y:['c','d'], visible: 'legendonly'},{y:['e','f']}],
    {yaxis:{
        tickvals:['a','b','c','d','e','f'],
        ticktext:['OFF','ON     ','OFF','ON     ','OFF','ON     '],
        categoryorder: 'category ascending'
    }}
)

Screen Shot 2020-11-13 at 5 20 08 PM
And worse, if I set a trace to visible: false instead of 'legendonly' an error is thrown. Doesn't seem to be directly related to #5267 / #5268 as I see the problem both before and after that fix...

@alexcjohnson alexcjohnson added the bug something broken label Nov 13, 2020
@ciuliene
Copy link
Author

You can use a category axis. Might just work exactly as you have it but with yaxis.type='category', but then you don't need to encode the values as numbers, any unique values will do. Here I just used strings to get a category axis automatically:

Plotly.newPlot(gd,
    [{y: ['a','b']},{y:['c','d']},{y:['e','f']}],
    {yaxis:{tickvals:['a','b','c','d','e','f'],ticktext:['OFF','ON     ','OFF','ON     ','OFF','ON     ']}}
)

Screen Shot 2020-11-13 at 5 11 18 PM

That said @archmoj I think there's a bug here when I try to include categoryorder, which is necessary to ensure the Off values always come before the On values: Then when I hide a trace via the legend, its categories are still there:

Plotly.newPlot(gd,
    [{y: ['b','a']},{y:['c','d'], visible: 'legendonly'},{y:['e','f']}],
    {yaxis:{
        tickvals:['a','b','c','d','e','f'],
        ticktext:['OFF','ON     ','OFF','ON     ','OFF','ON     '],
        categoryorder: 'category ascending'
    }}
)

Screen Shot 2020-11-13 at 5 20 08 PM
And worse, if I set a trace to visible: false instead of 'legendonly' an error is thrown. Doesn't seem to be directly related to #5267 / #5268 as I see the problem both before and after that fix...

Hey @alexcjohnson , I've done it! I managed to have stacked binaries using, as you told me, type: "category", categoryorder: "array", and categoryarray. Each time the user clicks on the legend the categoryarray property is reloaded. It now works exactly as I wanted

I haven't checked the case with an "invisible" trace (visible : false) because I don't use it. Anyway thank you so much for your help! 1000 points for you! 👍

@alexcjohnson
Copy link
Collaborator

@ciuliene OK great, glad that worked! There's still a bug here though, so I'll leave the issue open until we address it.

@gvwilson
Copy link
Contributor

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

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

No branches or pull requests

3 participants