Skip to content

Instantly share code, notes, and snippets.

@DuaneNielsen
Created October 31, 2020 19:43
Show Gist options
  • Save DuaneNielsen/a2d5082e31d6157823c7ae7f7e02efc0 to your computer and use it in GitHub Desktop.
Save DuaneNielsen/a2d5082e31d6157823c7ae7f7e02efc0 to your computer and use it in GitHub Desktop.
How to OO in matplotlib
from matplotlib import pyplot as plt
#rows, columns
layout = (2, 1)
fig = plt.figure(figsize=(12, 12), dpi=80)
fig.canvas.set_window_title(title='matplotlib object oriented demo')
positions = fig.add_subplot(*layout, 1, )
positions.set_title('scatter plot')
positions.scatter(x=[0.5, 0.75, 1], y=[0.5, 0.75, 1])
velocity = fig.add_subplot(*layout, 2, )
velocity.set_title('line plot')
velocity.plot([0.5, 1], [1, 0.5], label='one')
velocity.plot([0.5, 1], [1, 2], label='two')
velocity.legend()
fig.canvas.draw()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment