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.

Reformatting ordinal date value

See original GitHub issue

I am trying to reformat the axis for an ordinal date value to show month year as follows:

alt.Chart(by_district).mark_rect().encode(
    alt.X('month_year:O', title='Month', axis=alt.Axis(format='%b %Y')),
    alt.Y('DISTRICT', title=['Police District'], axis=alt.Axis(grid=False),
          sort=['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',
                '13', '14', '15', '16', '17', '18', '19', '20', '21', '22',
                '23', '24', '25', '31', '41', '51']),
    alt.Color('isr_count', title=['Total ISRs per Month'])
).properties(
title={
  "text": ["Monthly ISRs by Police District 2016-2018"], 
  "subtitle": ["Total ISRs per month vary across police districts and over time.",
               "Source: Chicago Police Department Investigatory Stop Reports*"]
}
)

The above code does not output anything. When I remove the axis argument in alt.X as follows, my I do get output as shown in the image, but my dates are not formatted as I want them to be (Jan 2016, Feb 2016, etc.). Why might this be happening?

alt.Chart(by_district).mark_rect().encode(
    alt.X('month_year:O', title='Month'),
    alt.Y('DISTRICT', title=['Police District'], axis=alt.Axis(grid=False),
          sort=['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12',
                '13', '14', '15', '16', '17', '18', '19', '20', '21', '22',
                '23', '24', '25', '31', '41', '51']),
    alt.Color('isr_count', title=['Total ISRs per Month'])
).properties(
title={
  "text": ["Monthly ISRs by Police District 2016-2018"], 
  "subtitle": ["Total ISRs per month vary across police districts and over time.",
               "Source: Chicago Police Department Investigatory Stop Reports*"]
}
)

image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, Feb 6, 2020

Try using a time unit instead of an axis format string; e.g.

alt.X('yearmonth(month_year):O', title='Month')

I think the reason the format string didn’t work is because you’re specifying that your data is of ordinal type, not temporal type.

0reactions
chankristacommented, Feb 11, 2020

Got it, thanks for the speedy assistance!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ordinal date - Wikipedia
An ordinal date is a calendar date typically consisting of a year and a day of the year or ordinal day number an...
Read more >
How to convert date to ordinal date format in Excel?
1. Select a cell that used to place the ordinal date, click Kutools > Formula Helper > Date & Time > Convert date...
Read more >
How do you format the day of the month to say "11th", "21st" or ...
Simply create a day of some format but include %s%s to add the day and ordinal later. ZonedDateTime ldt = ZonedDateTime.now(); String format...
Read more >
Converting between Julian and Gregorian date formats - IBM
This format of date is a combination of year plus a relative day number within the year, which is more correctly called an...
Read more >
What is date.fromordinal(ordinal) in Python? - Educative.io
The fromordinal() method is used to convert a Gregorian ordinal to an equivalent Gregorian date format. It is a reverse method of toordinal()...
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