Skip to content

Instantly share code, notes, and snippets.

@psinger
Last active March 17, 2018 10:59
Show Gist options
  • Save psinger/3d39a0294585ff33aa1f03bf138c891c to your computer and use it in GitHub Desktop.
Save psinger/3d39a0294585ff33aa1f03bf138c891c to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
def plot_dict(d, xlabel, ylabel, filename):
''' Plotting the keys and values given in dictionary
d = dictionary
xlabel = label for x-axis
ylabel = label for y-axis
filename = output filename
'''
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(d.values(), marker='o')
ticks = np.arange(len(d.keys()))
ax.set_xticks(ticks)
ax.set_xticklabels(d.keys())
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
plt.savefig(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment