The plt.*
settings usually apply to matplotlib's current plot; with plt.subplot
, you're starting a new plot, hence the settings no longer apply to it. You can share labels, ticks, etc., by going through the Axes
objects associated with the plots (see examples here), but IMHO this would be overkill here. Instead, I would propose putting the common "styling" into one function and call that per plot:
def applyPlotStyle():
plt.xlabel('Size')
plt.ylabel('Time(s)');
plt.title('Matrix multiplication')
plt.xticks(range(100), rotation=30, size='small')
plt.grid(True)
plt.subplot(211)
applyPlotStyle()
plt.plot(xl, serial_full, 'r--')
plt.plot(xl, acc, 'bs')
plt.plot(xl, cublas, 'g^')
plt.subplot(212)
applyPlotStyle()
plt.yscale('log')
plt.plot(xl, serial_full, 'r--')
plt.plot(xl, acc, 'bs')
plt.plot(xl, cublas, 'g^')
On a side note, you could root out more duplication by extracting your plot commands into such a function:
def applyPlotStyle():
plt.xlabel('Size')
plt.ylabel('Time(s)');
plt.title('Matrix multiplication')
plt.xticks(range(100), rotation=30, size='small')
plt.grid(True)
def plotSeries():
applyPlotStyle()
plt.plot(xl, serial_full, 'r--')
plt.plot(xl, acc, 'bs')
plt.plot(xl, cublas, 'g^')
plt.subplot(211)
plotSeries()
plt.subplot(212)
plt.yscale('log')
plotSeries()
On another side note, it might suffice to put the title at the top of the figure (instead of over each plot), e.g., using suptitle
. Similary, it might be sufficient for the xlabel
to only appear beneath the second plot:
def applyPlotStyle():
plt.ylabel('Time(s)');
plt.xticks(range(100), rotation=30, size='small')
plt.grid(True)
def plotSeries():
applyPlotStyle()
plt.plot(xl, serial_full, 'r--')
plt.plot(xl, acc, 'bs')
plt.plot(xl, cublas, 'g^')
plt.suptitle('Matrix multiplication')
plt.subplot(211)
plotSeries()
plt.subplot(212)
plt.yscale('log')
plt.xlabel('Size')
plotSeries()
plt.show()