I am currently doing some graphics using an online book hosted by sagemath.
This is an example of the code I'm doing to try to create a graph:
myplot = list_plot(zip(range(20), range(20)), color='red') myplot2 = list_plot(zip(range(20), [i*2 for i in range(20)]), color='blue') combined = myplot + myplot2 combined.show()
This is very simple - there are essentially two scatterplots mapped to each other.
Is there a way to easily add axis labels, legend, and possibly a title?
I managed to crack a solution that allows me to add axis labels, but it looks very ugly and stupid.
from matplotlib.backends.backend_agg import FigureCanvasAgg def make_graph(plot, labels, figsize=6): mplot = plot.matplotlib(axes_labels=labels, figsize=figsize) mplot.set_canvas(FigureCanvasAgg(mplot)) subplot = mplot.get_axes()[0] subplot.xaxis.set_label_coords(x=0.3,y=-0.12) return mplot a = make_graph(combined, ['x axis label', 'y axis label']) a.savefig('test.png')
Is there an easier way to add axis labels, legend and title?
source share