I was trying to do a comparison of runtime between Naive matrix multiplication and Strassen's. For this, I was recording the runtime for a different dimension of the matrices. Then I was trying to plot the result in the same graph for the comparison.
But the problem is the plotting is not showing the proper result.
- Here is the data...
2 3142 3 3531 4 4756 5 5781 6 8107
The leftmost column is denoting n
, the dimension and rightmost column is denoting execution time.
The above data is for Naive method and the data for Strassen is in this pattern too.
I'm inserting this data to a pandas dataframe. And after plotting the data the image looks like this:
Here blue is for Naive and green is for Strassen's This is certainly not true as Naive cannot be constant. But my code was correct. SO I decided to plot them separately and these are the result:
As you can see it might happen because the scaling in Y axis is not the same? Is this the reason?
The code I'm implementing for plotting is:
fig = plt.figure()
data_naive = pd.read_csv('naive.txt', sep="\t", header=None)
data_naive.columns = ["n", "time"]
plt.plot(data_naive['n'], data_naive['time'], 'g')
data_strassen = pd.read_csv('strassen.txt', sep="\t", header=None)
data_strassen.columns = ["n", "time"]
plt.plot(data_strassen['n'], data_strassen['time'], 'b')
plt.show()
fig.savefig('figure.png')
What I tried to work out?
fig = plt.figure()
data_naive = pd.read_csv('naive.txt', sep="\t", header=None)
data_naive.columns = ["n", "time"]
data_strassen = pd.read_csv('strassen.txt', sep="\t", header=None)
data_strassen.columns = ["n", "time"]
ax = data_naive.plot(x='n', y='time', c='blue', figsize=(20,10))
data_strassen.plot(x='n', y='time', c='green', figsize=(20,10), ax=ax)
plt.savefig('comparison.png')
plt.show()
But no luck!!!
How to plot them in the same figure without altering their actual orientation?
IIUC: Here is a solution using
twinx
Result produced: