Created
January 26, 2021 22:12
-
-
Save akanik/bbde941f57365958607371d38232f9b4 to your computer and use it in GitHub Desktop.
template for those pandas charts you love so much
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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