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
Using the index of a data frame as a (default) x coordinate when providing a data source #4580
Comments
I believe this is solved, can you try the latest dev build |
I tried to pip install from github ( Could you point me to the reference for the dev branch (if it is uploaded somewhere)? You mentioned that this feature is already implemented, but you did not say what the proper arguments for the function call are. |
Pip install from github will not work because pip is not capable of building the coffeescript and typescript components. There are simple instructions for installing pre-built dev builds in the docs: http://bokeh.pydata.org/en/latest/docs/installation.html#developer-builds |
Thanks for the pointer. It is still not working in the dev release:
The code above produces a plot where all data source entries are in the correct y position, but all of them are at x=0. How can I specify that the x coordinate should be the data source index? |
does |
|
Hi @Krastanov The issue is that you have to specify which column should be the "x" column. If you don't specify the "x" value, the default behavior in bokeh.plotting is to try to find a column called "x" in your ColumnDataSource (which doesn't exist). One tricky thing here is that you're using a named index ('timestamp') in pandas. That name is carried over when you create a ColumnDataSource, so that your source probably looks like: ds = ColumnDataSource(df)
print(ds.data) # this lets you inspect the data dict
# the ts_n values would be the actual timestamps from the df
> {'timestamp': [ts_1, ts_2, ts_3, ts_4, ts_5], 'avg': [0.9, 0.8, 0.7, 0.8, 0.9]} It would work if you use:
|
I see, I did not know that indices (as opposed to normal columns) can be named. Thanks. |
For some data frames the index has quite useful semantic meaning. Particularly so for
datetime
indices. It would be useful if the api has an option to use the index as a coordinate.Example given here: https://stackoverflow.com/questions/37904231/plot-a-pandas-dataframe-using-the-dataframe-index-for-x-coordinate-in-bokeh/37905026#37905026
The text was updated successfully, but these errors were encountered: