Skip to content

Instantly share code, notes, and snippets.

@theDestI
Last active May 19, 2022 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theDestI/3d5f877b2db9697ad99df69c1d390c88 to your computer and use it in GitHub Desktop.
Save theDestI/3d5f877b2db9697ad99df69c1d390c88 to your computer and use it in GitHub Desktop.
def plot_against_benchmark(series, benchmark, figsize = (13, 10), two_axis = False):
"""
Plots a series against a benchmark.
:param series: The series to be plotted.
:param benchmark: The benchmark to be plotted.
:return: The plot.
"""
plt.figure(figsize = figsize)
ax1 = series.plot(label=series.name, color='blue', legend = True)
if two_axis:
ax2 = ax1.twinx()
ax2.plot(benchmark, label=benchmark.name, color='red')
else:
benchmark.plot(label=benchmark.name, color='red', ax=ax1, legend = True)
return plt.gcf()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment