Skip to content

Instantly share code, notes, and snippets.

@akanik
Created January 26, 2021 22:12
Show Gist options
  • Save akanik/bbde941f57365958607371d38232f9b4 to your computer and use it in GitHub Desktop.
Save akanik/bbde941f57365958607371d38232f9b4 to your computer and use it in GitHub Desktop.
template for those pandas charts you love so much
import pandas as pd
import numpy as np
import glob
import matplotlib.pyplot as plt
import re
def linechart(df, x_dim, y_dim, xaxis, yaxis, title):
fig, ax = plt.subplots(figsize=(15, 7))
if x_dim == 'index':
df[y_dim].plot(ax=ax, grid=True)
else:
df.set_index(x_dim)[y_dim].plot(ax=ax, grid=True)
#adds a title and axes labels
ax.set_title(title)
ax.set_xlabel(xaxis)
ax.set_ylabel(yaxis)
#removing top and right borders
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment