Use dataframe index as X axis
See original GitHub issueHi, I am trying to use a pandas dataframe as the Chart data in altair, but I need to use the index of the dataframe as the X axis. My dataframe looks like this
with index of type
DatetimeIndex(['2014-04-01 00:00:00', '2014-04-01 00:05:00',
'2014-04-01 00:10:00', '2014-04-01 00:15:00',
'2014-04-01 00:20:00', '2014-04-01 00:25:00',
'2014-04-01 00:30:00', '2014-04-01 00:35:00',
'2014-04-01 00:40:00', '2014-04-01 00:45:00',
...
'2014-04-14 23:10:00', '2014-04-14 23:15:00',
'2014-04-14 23:20:00', '2014-04-14 23:25:00',
'2014-04-14 23:30:00', '2014-04-14 23:35:00',
'2014-04-14 23:40:00', '2014-04-14 23:45:00',
'2014-04-14 23:50:00', '2014-04-14 23:55:00'],
dtype='datetime64[ns]', name='timestamp', length=4032, freq=None)
I tried something like this, but to no use.
from altair import Chart, X, Y
Chart(data1).mark_line().encode(
X('index'),
Y('value'),
)
How should I do it? I know that if I convert my index to a column it can do the trick, but is there another way?
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Using a Pandas dataframe index as values for x-axis in ...
You can use yourDataFrame.plot(use_index=True) to use the DataFrame Index On X-Axis. The "use_index=True" sets the DataFrame Index on the ...
Read more >Using a Pandas dataframe index as values for x-axis ... - Reddit
I have time series in a Pandas dateframe with a number of columns which I'd like to plot. Is there a way to...
Read more >How to Use Index in Pandas Plot (With Examples) - Statology
You can use one of the following methods to use the values in the index of a pandas DataFrame as the x-axis values...
Read more >Pandas: Create matplotlib plot with x-axis label not index
I've been using matplotlib a bit recently, and wanted to share a lesson I learnt about choosing the label of the x-axis.
Read more >pandas.DataFrame.plot — pandas 0.13.1 documentation
Make line, bar, or scatter plots of DataFrame series with the index on the x-axis using matplotlib / pylab. Parameters : frame :...
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
Altair only recognizes column data; it ignores index values. You can plot the index data by first resetting the index:
@afonit Thanks, that works. I apologize for the noob question, but I found it surprisingly difficult to do something as simple, and
.reset_index()
doesn’t seem very intuitive.