Issue
How should I plot three different averages sharing x-axis.
My attempt with errorbars showing also standard deviation doesn't let me insert more than one "score", resulting in a single line plot
This is what I did currently
times_alg_1_sparse = times_alg1['Sparse']
avg_alg1_50_sparse, std_alg1_50_sparse = extract_statistics(times_alg_1_sparse.iloc[0])
avg_alg1_200_sparse, std_alg1_200_sparse = extract_statistics(times_alg_1_sparse.iloc[1])
avg_alg1_600_sparse, std_alg1_600_sparse = extract_statistics(times_alg_1_sparse.iloc[2])
x = np.array(times_alg_1_sparse.index)
y = np.array([avg_alg1_50_sparse*1000, avg_alg1_200_sparse*1000, avg_alg1_600_sparse*1000])
e = np.array([std_alg1_50_sparse*1000, std_alg1_200_sparse*1000, std_alg1_600_sparse*1000])
fig, ax = plt.subplots()
ax.errorbar(x, y, e, mfc='red', linestyle='solid', marker='^', color='red')
plt.ylim(0)
plt.show()
Solution
You just have to call your plot function any times you want with different values.
I suppose your avg
and std
vectors have the same size, because they are output of the same function extract_statistics
. You may have a problem with your vector x
. Maybe the size of this vector does not match the size of avg
and std
vectors.
In the following solution we have three pairs of vectors avg
and std
: 50, 200, 600. We combine the 3 vectors in one vector y
and e
. So, in each iteration of the following for
loop, we use the same vector x
for the 3 different indexes from the vectors y
and e
. For this to work, we suppose the vector x
and each element of y
and e
have the same size.
When we call something like y[:,0]
, for example, we are slicing the vector y
and getting all the values of the first column of this vector.
times_alg_1_sparse = times_alg1['Sparse']
avg_alg1_50_sparse, std_alg1_50_sparse = extract_statistics(times_alg_1_sparse.iloc[0])
avg_alg1_200_sparse, std_alg1_200_sparse = extract_statistics(times_alg_1_sparse.iloc[1])
avg_alg1_600_sparse, std_alg1_600_sparse = extract_statistics(times_alg_1_sparse.iloc[2])
x = np.array(times_alg_1_sparse.index)
y = np.array([avg_alg1_50_sparse*1000, avg_alg1_200_sparse*1000, avg_alg1_600_sparse*1000])
e = np.array([std_alg1_50_sparse*1000, std_alg1_200_sparse*1000, std_alg1_600_sparse*1000])
colors = ['red', 'green', 'blue']
for k in range(3):
plt.errorbar(x, y[:,k], e[:,k], mfc=colors[k], linestyle='solid', marker='^', color=colors[k])
plt.ylim(0)
plt.show()
You are trying to use subplots
. What is indicated when you want to plot, in the same figure, more than one graph.
Answered By - Lorran Sutter
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.