question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom order of points drawing a line

See original GitHub issue

Hi there folks. @jakevdp I’m happy I found your comment here #689

ordering of points in a line as well. I used that in an example here: 2098f8d

Right now I’m having trouble drawing a line exactly because of the ordering issue. My problem is that I have to specify the ordering by providing the values, more or less like this:

alt.Chart(data).mark_line().encode(
        x='x:Q',
        y='y:Q',
        order=alt.Order('topic:N', sort=['Some Topic', 'Amazing Topic', 'Some Other', 'Minor Topic'])
    )

but I’m getting:

altair.vegalite.v2.schema.channels.Order->sort, validating 'anyOf'

['Some Topic', 'Amazing Topic', 'Some Other', 'Minor Topic'] is not valid under any of the given schemas

Is there any workaround for this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Mar 1, 2020

Currently you can control the stack order using an order encoding, and the legend order using the sort:

import altair as alt
import pandas as pd

df = pd.DataFrame({
    'label': ['Leave', 'OT', 'Roster'],
    'hours': [5, 6, 7]
})

alt.Chart(df).transform_calculate(
    order="{'Leave': 0, 'Roster': 1, 'OT': 2}[datum.label]"
).mark_bar().encode(
    x='hours',
    color=alt.Color('label', sort=['Leave', 'Roster', 'OT']),
    order='order:Q'
)

visualization - 2020-03-01T063033 916

When https://github.com/vega/vega-lite/issues/1734 is addressed, this will be easier.

0reactions
ihightowercommented, Mar 1, 2020

can someone explain how this is solved clearly with example code. I also want to sort the stacked bars in a custom order. Lower stack say is ‘Leave’, Middle stack is ‘Roster’, Upper stack is ‘OT’ for Work Types. just ascending and descending for sort order doesn’t cut it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Complete Guide to Line Charts | Tutorial by Chartio
Line charts are a fundamental chart type generally used to show change in values across time. Learn how to best use this chart...
Read more >
Organize Points and Draw the Line - matlab - Stack Overflow
I've found the right answer (by Gunther Struyf): Sort Coordinates Points in Matlab. In order to visualize the final result just add to...
Read more >
Drawing lines from points in QGIS - GIS Stack Exchange
The simplest way is to use the points to create the line. To do this in QGIS use the Points2One plugin. Install this...
Read more >
Draw or delete a line or connector - Microsoft Support
Draw a line with connection points · On the Insert tab, in the Illustrations group, click Shapes. Insert Shapes button · Under Lines,...
Read more >
EscherSketch
An imperfect tool for drawing and exploring symmetrical patterns and designs. It can export pictures ... line, draws single line segments between two...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found