Last active
November 21, 2020 17:15
-
-
Save uomodellamansarda/197168186809366cd5996d502ea2e850 to your computer and use it in GitHub Desktop.
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
#this function will plot the barpolot for the different balance lines | |
#the default color for the main bar is midnight blue | |
#but you can change in pink, darkpink or magenta it is Disney! | |
def bar_plot(x1,y1,y2,y_2_label='Compared Variable',title="You Forgot The Title",bar_col='midnightblue'): | |
fig, ax = plt.subplots(figsize=(10,5), | |
facecolor='white', dpi=300) | |
twenty=np.full(len(x1),20) | |
forty=np.full(len(x1),40) | |
ax.bar(x1, y1, label=y_2_label,color=bar_col) | |
ax.bar(x1, y2, color='lightgrey', bottom=y1, | |
label='Other Revenue Streams',alpha=0.6) | |
ax.set_ylabel('Revenues Contribution %') | |
ax.plot(x1,twenty,'--',color='yellow',alpha=0.9) | |
ax.plot(x1,forty,'--',color='red',alpha=0.9) | |
ax.set_title(title) | |
ax.legend() | |
ax.yaxis.tick_left() | |
ax.yaxis.set_ticks_position("both") | |
water_x=(min(x1)+max(x1))/2 | |
water_y=max(y1)/3 | |
print(water_x) | |
print(water_y) | |
water_p=(min(x1)+max(x1))/2 | |
plt.text(water_x, water_y, 'Data Elaboration Ing. Andrea Ciufo. Data Source: https://data.world/', | |
fontsize=10, color='gray', | |
ha='center', va='top') | |
plt.text(water_p+5.2, 20+5,'20%', | |
fontsize=10, color='yellow', | |
ha='center', va='top') | |
plt.text(water_p+5.2, 40+5,'40%', | |
fontsize=10, color='darkred', | |
ha='center', va='top') | |
plt.text(water_p-5.2, 20+5,'20%', | |
fontsize=10, color='yellow', | |
ha='center', va='top') | |
plt.text(water_p-5.2, 40+5,'40%', | |
fontsize=10, color='darkred', | |
ha='center', va='top') | |
plt.show() | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment