Skip to content

Instantly share code, notes, and snippets.

@Zmey56
Created August 23, 2022 14:22
Show Gist options
  • Save Zmey56/d1211368a182c0a300ff9e2e08fdb0e1 to your computer and use it in GitHub Desktop.
Save Zmey56/d1211368a182c0a300ff9e2e08fdb0e1 to your computer and use it in GitHub Desktop.
def get_plot(data):
fig, axes = plt.subplots(2, 2, figsize = (16 , 10))
# fig.subtitle("Feed statistics for the previous 7 days")
plot_dict = {(0,0):{'y':'DAU', 'title': 'Unique users'},
(0,1):{'y':'likes', 'title': 'Likes'},
(1,0):{'y':'views', 'title': 'Views'},
(1,1):{'y':'CTR', 'title': 'CTR'}}
for i in range(2):
for j in range(2):
sns.lineplot(ax=axes[i,j], data=data, x='date', y=plot_dict[(i,j)]['y'])
axes[i, j].set_title(plot_dict[(i,j)]['title'])
axes[i, j].set_xlabel(None)
axes[i, j].set_ylabel(None)
for ind, label in enumerate(axes[i, j].get_xticklabels()):
if ind % 3 == 0:
label.set_visible(True)
else:
label.set_visible(False)
plot_object = io.BytesIO()
plt.savefig(plot_object)
plot_object.name = 'feed_stat.png'
plot_object.seek(0)
plt.close()
return plot_object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment