1

I'm trying to plot a graph using Bokeh. I did it using matplotlib but I can't figure out how I can plot 2D array using Bokeh.

This is my code for plotting with matplotlib:

[row, col] = point_data.shape
# select columns names
text = point_data.columns
# find string index:
range_ind = np.array(text.str.find('Range_cm')) > -1
range_cm_mat = point_data.iloc[0:row, range_ind].values
plt.figure(figsize=(19, 10))
plt.plot(range_cm_mat, '.', markersize=0.5, color='#1f77b4')
plt.show()

My data I'm plotting is from a CSV file and it is filtered by the string above.

Please help me figure out how I can show this plot with Bokeh library

This is what I tried and it isn't the way...

def make_scatter(title, x_title, y_title, x, y):
    p = figure(title=title, toolbar_location="below", background_fill_color="#fafafa")
    p.circle(x, y)  # , alpha=0.5)
    p.y_range.start = 0
    p.legend.location = "center_right"
    p.legend.background_fill_color = "#fefefe"
    p.xaxis.axis_label = x_title
    p.yaxis.axis_label = y_title
    p.grid.grid_line_color = "white"
    return p

x = np.arange(1, np.size(plot[0]), 1)
for i in range (np.size(plot[0])):
    p1 = make_scatter("Range/Frames", 'Range [m]', 'Frames', [pt[i] for pt in plot], x)
show(p1)

This is how the data looks like:

2D array:

1
  • Bokeh data sources for scatters are column-based. If your original data is in 2d-arrays you will need to flatten everything to 1d arrays before passing to Bokeh. See this chapter of the docs: docs.bokeh.org/en/latest/docs/user_guide/data.html Commented Apr 6, 2022 at 14:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.