Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. from bokeh.plotting import figure, show, output_file, ColumnDataSource
  4. from bokeh.models import HoverTool
  5. from bokeh.models.formatters import DatetimeTickFormatter
  6. from bokeh.models.ranges import Range1d
  7. from bokeh.models.axes import LinearAxis
  8.  
  9. output_file("final.html")
  10.  
  11. df = pd.DataFrame(all_data)
  12.  
  13. hover = HoverTool(
  14. tooltips=[
  15. ( 'time', '@time{%R}'),
  16. ( 'bmp', '@bmp{000.}'),
  17. ( 'cad', '@cad'),
  18. ( 'spd', '@spd')
  19. ],
  20.  
  21. formatters={
  22. 'time' : 'datetime',
  23. },
  24.  
  25. mode='vline'
  26. )
  27.  
  28. p = figure(x_axis_type="datetime", plot_width=600, plot_height=300, tools=[hover], title="all-data_time_hover")
  29.  
  30. # range for each data field
  31. p.y_range = Range1d(0, 220) # bmp
  32. p.extra_y_ranges = {"cad": Range1d(start=0, end=140), # RunCadence
  33. "spd": Range1d(start=0, end=10.0) } # Speed
  34.  
  35. # add the extra range to the right of the plot
  36. p.add_layout(LinearAxis(y_range_name="cad"), 'right')
  37. p.add_layout(LinearAxis(y_range_name="spd"), 'right')
  38.  
  39. # set axis text color
  40. p.yaxis[0].major_label_text_color = "red"
  41. p.yaxis[1].major_label_text_color = "blue"
  42. p.yaxis[2].major_label_text_color = "purple"
  43.  
  44.  
  45. ## plot !
  46. p.line(df['time'], df['bmp'], legend='bmp', line_color="red", muted_color='red', muted_alpha=0.2)
  47.  
  48. p.line(df['time'], df['cad'], legend='cad', line_color="blue", muted_color='blue', muted_alpha=0.2, y_range_name='cad')
  49.  
  50. p.line(df['time'], df['spd'], legend='spd', color="purple", muted_color='purple', muted_alpha=0.2, y_range_name='spd')
  51.  
  52.  
  53. # setting for legend
  54. p.legend.location = "top_right"
  55. p.legend.click_policy="mute"
  56.  
  57.  
  58.  
  59. show(p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement