I am trying to plot a big graph. I want to plot a range in X_axis. Below you can find what I am trying to do, which I made using matplotlib.
import matplotlib.pyplot as plt
import csv
with open('test.csv','r') as csvfile :
rows = list(csv.reader(csvfile, delimiter=','))[1:]
rows.sort(key = lambda x: int(x[1]))
for row in rows:
start, end, data = int(row[2]), int(row[3]), int(row[1])
x = [start, end]
y = [data, data]
plt.plot(x, y, color = 'b', marker='o')
plt.xlabel('time(milliseconds)')
plt.ylabel('Amount of Data(bytes)')
plt.title('VFS layer Read only graph')
plt.grid(True)
plt.savefig('VR.png')
plt.show()
This is the image result for the plot using matplotlib. I want to do the same using Bokeh ColumnDataSource.
df = pd.read_csv('test.csv')
data = ColumnDataSource(data={
'x':df['x'],
**'y':df['y1']+df['y2'],** # I could not give range in here
})
plot1 = figure()
plot1.cross(x='x',y='y',source=data, color='red', size=10, alpha=0.8)
plot2 = figure()
output_file('First_try.html')
show(plot1)
Segments should help with that: Plotting with basic glyphs — Bokeh 2.4.2 Documentation
And the circles at the ends of the segments could be plotted with plot.circle.
Regarding the data - just store both y1 and y2 as separate columns in the data source.
I have changed the code as you said, but it is giving error
ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name. This could either be due to a misspelling or typo, or due to an expected column being missing. : key "x0" value "x", key "x1" value "x", key "y0" value "y1", key "y1" value "y2" [renderer: GlyphRenderer(id='6297', ...)]
This is the csv file :
id x y1 y2
0 1 2 5 8
1 2 3 4 9
I think there is a limitation for segment while there isn’t for circle. It is working fine when I executed with 5 lines of information for segment but with 30 lines it is not drawing anythin.
Sorry, it was working fine. The line width was small and the amount of data was too big, that is why the lines were disappearing. It works fine now. Thanks for kind cooperation.