Skip to content

Instantly share code, notes, and snippets.

@phizaz
Last active February 22, 2017 10:04
Show Gist options
  • Save phizaz/194ac269c3f3e2787ecc78c5b31722f2 to your computer and use it in GitHub Desktop.
Save phizaz/194ac269c3f3e2787ecc78c5b31722f2 to your computer and use it in GitHub Desktop.
Matplotlib: plotting with x-ticks labels
def plot(keys: list, vals: list):
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x = range(len(vals))
ax.set_xticks(x) # plot every tick
ax.set_xticklabels(keys, rotation=90)
ax.plot(x, vals)
fig.savefig('output.png', bbox_inches='tight') # bbox_inches='tight' to prevent text-overflow out of the frame
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment