Reputation: 794
I'm trying to plot a multi_line in Bokeh but for some reason it's not working. I've read in a file with pandas:
roads = pd.read_csv('path/file.csv')
and the resulting dataframe looks like this:
osm_id code fclass name ref oneway maxspeed layer bridge tunnel x y
0 4264947 5152 cycleway NaN NaN B 0 0 F F [4.9223553, 4.9223667, 4.9223853] [52.3654363, 52.3654277, 52.3654169]
1 4270144 5124 pedestrian Dapperplein NaN B 0 0 F F [4.9279354, 4.9280225, 4.9280546, 4.928041, 4.... [52.3619809, 52.362025, 52.3621167, 52.3622213...
2 4270151 5153 footway Zeeburgerstraat NaN B 0 0 F F [4.9261096, 4.9260732, 4.9258198] [52.3663263, 52.3662732, 52.3661229]
3 4270806 5152 cycleway Roomtuintjes NaN B 0 0 F F [4.9308652, 4.9308238, 4.9307548, 4.9304676, 4... [52.3659402, 52.3657291, 52.3655389, 52.364919...
4 4277440 5124 pedestrian Vondelpark NaN B 0 0 F F [4.881478, 4.8816828, 4.881693] [52.361566, 52.361699, 52.3617067]
When I try to plot the coordinates with bokeh
source = ColumnDataSource(roads)
q = figure(title= "Roads", plot_width=900, plot_height=900)
q.multi_line('x', 'y', source = source, color='blue', line_width=0.5)
show(q)
It outputs an empty plot.
What is going wrong and is there someone that can help me?
Thanks!
Upvotes: 1
Views: 77
Reputation: 863701
Problem is list in columns, here string repr of list. So first are converted both columns to lists::
import ast
roads = pd.read_csv('path/file.csv')
roads['x'] = roads['x'].apply(ast.literal_eval)
roads['y'] = roads['y'].apply(ast.literal_eval)
Another solution:
import ast
conv = lambda x: ast.literal_eval(x)
roads = pd.read_csv('path/file.csv', converters={'x':conv, 'y':conv})
source = ColumnDataSource(roads)
q = figure(title= "Roads", plot_width=900, plot_height=900)
q.multi_line('x', 'y', source = source, color='blue', line_width=0.5)
show(q)
Upvotes: 1