Skip to content

Instantly share code, notes, and snippets.

@cwidmer
Last active December 30, 2015 08:39
Show Gist options
  • Save cwidmer/7804306 to your computer and use it in GitHub Desktop.
Save cwidmer/7804306 to your computer and use it in GitHub Desktop.
snippet to create matplotlib plot with title, grid and externally located legend
import pylab
data1 = [1,2,3,4]
data2 = [2,3,4,5]
pylab.plot(data1, "-o", label="meh")
pylab.plot(data2, "-o", label="arr")
pylab.title("example")
pylab.grid(True)
ax = pylab.axes()
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
pylab.savefig("test.pdf")
#pylab.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment