Updating the user-defined function for plotting
Recall the function to make plots from an earlier exercise:
def make_plot(dataset, ratio, comp_type):
whole_dat = []
for industry in comp_type:
dat = dataset.loc[dataset["comp_type"]==industry]
dat_avg = dat.pivot_table(index="Year",
values=ratio).reset_index()
dat_avg["company"] = f"Avg {type}"
dat_avg["comp_type"] = industry
whole_dat.append(pd.concat([dat,
dat_avg]))
plot_df = pd.concat(whole_dat).reset_index(drop=True)
sns.relplot(data=plot_df,
x="Year",
y="gross_margin",
hue="company",
col="comp_type",
kind="line")
plt.show()
plt.close()
Notice how this function can only make line plots with year on the x-axis. In this exercise, you will be introduced to an updated version of this function.
This exercise is part of the course
Analyzing Financial Statements in Python
Hands-on interactive exercise
Turn theory into action with one of our interactive exercises
