Reformatting ordinal date value
See original GitHub issueI 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*"]
}
)
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try using a time unit instead of an axis format string; e.g.
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.
Got it, thanks for the speedy assistance!