-
Notifications
You must be signed in to change notification settings - Fork 163
Alphabetically sort the legend in px.pie / vm.Graph while keeping slice order by value #1146
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
Comments
Hi @fpeucelle 👋 Thank you—we’re thrilled to hear that Vizro is supporting your work and that you enjoy using it. Vizro rebuilds the fig whenever the page is loaded or a filter is applied. Because the figure gets rebuilt each time, any settings like So something like below will hopefully resolve the issue.
If the problem persists, let us know and we will try to find other solution. Greetings to Argentina, |
I will close this issue now. If you have any further questions or if the issue persists, feel free to comment here and we’ll be happy to reopen it. |
Thank you, @nadijagraca 🙌. To clarify what I’m aiming for: Sort the pie‑chart slices in descending order by their value. Sort the legend alphabetically (A → Z), independent of the slice order. From your comment, I understand that this currently requires a custom figure function, and I admit my previous example wasn’t the best. 🤦♂️ What I’m attaching in this comment a self‑contained script with two captured functions (custom_pie and standard_pie) and a minimal dashboard that displays both charts side‑by‑side. obtained_charts.png – a screenshot of the results I get with that code (they don’t meet the desired ordering). desired_chart.png – a mock‑up of the final chart I’m trying to achieve (slices sorted ↓ by value, legend sorted ↑ alphabetically). I hope this makes the expected behavior clearer. I’m happy to adjust anything—thanks again for your help!
|
Hi @fpeucelle, Thank you for clarifying. The below custom_chart function appears to give me the correct version of the graph.
I've added the code below to prevent auto-sorting of the slices.
The below is the graph I get with the above adjustments. Let me know if this fixes the issue for you. Nadija, |
Hi again @nadijagraca , I’ve just retested with the current patch but, unfortunately, the slice values are now incorrect. In my dataset “Comodoro” should be 22 %, yet the updated chart shows 37 %. It looks like the fix re‑orders the slices correctly but recalculates the percentages based on the new order, so the visualization no longer reflects the real data. Could we explore another approach that keeps the descending slice order without altering the original values? Thanks anyway for your quick response and assistance! Cheers, |
Have you already looked into this topic?
Question
Hi Vizro team 👋,
First of all, thanks for the great work—Vizro is powering our judicial analytics dashboards and it’s been a pleasure to use. I have a question (and maybe a feature request) regarding pie‑chart legends.
When users switch filters or jump between tabs, the slice order (by value) can change from one state to another. Because the legend always mirrors that slice order, its entries shuffle around and users lose their visual bearings. An alphabetically fixed legend would reduce that cognitive load.
What I’ve tried
Question / Feature Request
Is there any built‑in way in Vizro or Plotly to break the coupling and:
keep the slice order driven by values, but supply an independent alphabetical order for the legend (so it stays stable across filter and tab changes)?
If not, would you consider adding something like legend_category_orders (analogous to category_orders but applied only to the legend)?
Thanks a lot for your time and for maintaining Vizro!
Greetings from Chubut, Argentina 🇦🇷
Francisco
Code/Examples
Which package?
vizro
Code of Conduct
The text was updated successfully, but these errors were encountered: