Skip to content

Instantly share code, notes, and snippets.

@kpsychas
Last active March 21, 2020 17:19
Show Gist options
  • Save kpsychas/68b20ced6861cc5f79fe429e35e6b6e6 to your computer and use it in GitHub Desktop.
Save kpsychas/68b20ced6861cc5f79fe429e35e6b6e6 to your computer and use it in GitHub Desktop.
Fancy Plot
import matplotlib.pyplot as plt
import numpy as np
def myplot(q, t, label, color=None, mean_in_legend=False, linewidth=0.5):
if mean_in_legend:
mean_total_q = np.dot(t, q) / t.sum()
plt.plot(t.cumsum(), q, color=color,
label='{} {:.2f}'.format(label, mean_total_q),
linewidth=linewidth)
else:
plt.plot(t.cumsum(), q, color=color, label='{}'.format(label),
linewidth=linewidth)
def plot_result(y, sim_type):
myplot(y, np.ones_like(y), sim_type, mean_in_legend=True)
def main():
# or fig, ax = plt.subplots()
fig = plt.figure(figsize=(6, 4.0))
ax = fig.add_subplot(111)
t = 1e-3 * np.arange(4000)
for f in [np.sin, np.cos, np.exp]:
plot_result(f(t), f.__name__)
fontsize = 14
legendsize = 6
plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
ax.tick_params(labelsize=fontsize)
ax.yaxis.offsetText.set_fontsize(fontsize)
plt.legend(loc='best', prop={'size': legendsize})
plt.xlabel('Simulation steps', fontsize=fontsize)
plt.ylabel('Total queue size', fontsize=fontsize)
plt.tight_layout(pad=1.4)
plt.show()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment