sns.lineplot(data=gb, x='InvoiceDate', y='Total', hue='BillingCountry')
# saving figure for book
sns.lineplot(data=gb, x='InvoiceDate', y='Total', hue='BillingCountry')
plt.tight_layout()
plt.savefig('seaborn_lineplot_color.png', dpi=300)
# black and white redundancy
sns.lineplot(data=gb, x='InvoiceDate', y='Total', hue='BillingCountry', style='BillingCountry')
# save figure for book
sns.lineplot(data=gb, x='InvoiceDate', y='Total', hue='BillingCountry', style='BillingCountry')
plt.tight_layout()
plt.savefig('seaborn_lineplot_color_dashes.png', dpi=300)
pip install labellines
sns.lineplot(data=gb, x='InvoiceDate', y='Total', hue='BillingCountry', style='BillingCountry', dashes=[(2, 1), (5, 2), ''])
from labellines import labelLines
pip install matplotlib-label-lines
from labellines import labelLines
f = plt.figure()
ax = f.gca()
for country in top_3_countries:
c_df = gb[gb['BillingCountry'] == country]
ax.plot(c_df['InvoiceDate'], c_df['Total'], label=country)
labelLines(ax.get_lines())
plt.xlabel('Year')
plt.ylabel('Cumulative Sales ($)')
# save image for book
plt.tight_layout()
plt.savefig('seaborn_lineplot_labels.png', dpi=300)
No comments:
Post a Comment