Stack Barchart applications with Python
Barchart modelling studies on especially Geophysics literatüre using as wide-range...
A multi-stack barchart how is designing.A good example for this question is presenting;
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
import pandas as pd
# y-axis in bold
rc('font', weight='bold')
# Values of each group
bars1 = [15, 12, 14, 13, 16,18,13,12,11,12,6,8,8,7,13,15,10,12,11,9,12,11,14,20,12,16,9,7,14,10]
bars2 = [9, 13, 11, 10, 11,4,5,8,9,8,11,5,10,10,4,8,12,9,6,7,8,5,5,10,10,11,12,6,6,5]
bars3 = [5, 5, 3, 2, 3,5,2,1,1,3,3,9,5,2,6,3,4,4,2,2,4,3,6,4,2,3,1,2,1,2]
bars4 = [0, 0, 0 , 0 , 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0]
# Heights of bars1 + bars2 (TO DO better).So;
#bars = [40, 35, 17, 12, 32]
#establishing for this process;
bars1=np.array(bars1)
bars2=np.array(bars2)
bars=bars1+bars2
#bars=list(bars)#Note:repr is establishing to 'array([a,b,c])' strucuture as comma separated
bars=list(bars)
print(bars)
bars2=list(bars2)
bars3=list(bars3)
bars1=list(bars1)
print(bars3)
bars1=np.array(bars1)
bars2=np.array(bars2)
bars3=np.array(bars3)
barsx=bars1+bars2+bars3
barsx=list(barsx)
# The position of the bars on the x-axis
r = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]
# Names of group and bar width
names = ['1/6/2018','2/6/2018','3/6/2018','4/6/2018','5/6/2018','6/6/2018','7/6/2018','8/6/2018','9/6/2018','10/6/2018','11/6/2018','12/6/2018','13/6/2018'
,'14/6/2018','15/6/2018','16/6/2018','17/6/2018','18/6/2018','19/6/2018','20/6/2018','21/6/2018','22/6/2018','23/6/2018','24/6/2018','25/6/2018'
,'26/6/2018','27/6/2018','28/6/2018','29/6/2018','30/6/2018']
barWidth = 1.0
# Create brown bars
p1=plt.bar(r, bars1, color='#7f6d5f', edgecolor='white', width=barWidth)
# Create green bars (middle), on top of the firs ones
p2=plt.bar(r, bars2, bottom=bars1, color='#557f2d', edgecolor='white', width=barWidth)
# Create green bars (top)
p3=plt.bar(r, bars3, bottom=bars, color='yellow', edgecolor='white', width=barWidth)
# Create red bars (most top)
p4=plt.bar(r, bars4, bottom=barsx, color='red', edgecolor='white', width=barWidth)
# Custom X axis
plt.xticks(r, names, fontweight='bold')
plt.xlabel("Dates")
# Custom Y axis
plt.ylabel('Number of Earthquakes as Magnitude')
#Title
plt.title('Monthly Magnitude Distributions(June 2018)')
plt.legend((p1[0], p2[0],p3[0],p4[0]),('M4_M4.5', 'M4.5_M5','M5_M5.8','M5.8_M6.5'))
# Show graphic
plt.show()
A file for solutioning to program;
You absolutely will evaluate that this program as base is on 3 layer stack concept...I explained 4 layer stack barchart.Thus,you will design to your multi-stack barchart on Project.
A multi-stack barchart how is designing.A good example for this question is presenting;
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
import pandas as pd
# y-axis in bold
rc('font', weight='bold')
# Values of each group
bars1 = [15, 12, 14, 13, 16,18,13,12,11,12,6,8,8,7,13,15,10,12,11,9,12,11,14,20,12,16,9,7,14,10]
bars2 = [9, 13, 11, 10, 11,4,5,8,9,8,11,5,10,10,4,8,12,9,6,7,8,5,5,10,10,11,12,6,6,5]
bars3 = [5, 5, 3, 2, 3,5,2,1,1,3,3,9,5,2,6,3,4,4,2,2,4,3,6,4,2,3,1,2,1,2]
bars4 = [0, 0, 0 , 0 , 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0]
# Heights of bars1 + bars2 (TO DO better).So;
#bars = [40, 35, 17, 12, 32]
#establishing for this process;
bars1=np.array(bars1)
bars2=np.array(bars2)
bars=bars1+bars2
#bars=list(bars)#Note:repr is establishing to 'array([a,b,c])' strucuture as comma separated
bars=list(bars)
print(bars)
bars2=list(bars2)
bars3=list(bars3)
bars1=list(bars1)
print(bars3)
bars1=np.array(bars1)
bars2=np.array(bars2)
bars3=np.array(bars3)
barsx=bars1+bars2+bars3
barsx=list(barsx)
# The position of the bars on the x-axis
r = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]
# Names of group and bar width
names = ['1/6/2018','2/6/2018','3/6/2018','4/6/2018','5/6/2018','6/6/2018','7/6/2018','8/6/2018','9/6/2018','10/6/2018','11/6/2018','12/6/2018','13/6/2018'
,'14/6/2018','15/6/2018','16/6/2018','17/6/2018','18/6/2018','19/6/2018','20/6/2018','21/6/2018','22/6/2018','23/6/2018','24/6/2018','25/6/2018'
,'26/6/2018','27/6/2018','28/6/2018','29/6/2018','30/6/2018']
barWidth = 1.0
# Create brown bars
p1=plt.bar(r, bars1, color='#7f6d5f', edgecolor='white', width=barWidth)
# Create green bars (middle), on top of the firs ones
p2=plt.bar(r, bars2, bottom=bars1, color='#557f2d', edgecolor='white', width=barWidth)
# Create green bars (top)
p3=plt.bar(r, bars3, bottom=bars, color='yellow', edgecolor='white', width=barWidth)
# Create red bars (most top)
p4=plt.bar(r, bars4, bottom=barsx, color='red', edgecolor='white', width=barWidth)
# Custom X axis
plt.xticks(r, names, fontweight='bold')
plt.xlabel("Dates")
# Custom Y axis
plt.ylabel('Number of Earthquakes as Magnitude')
#Title
plt.title('Monthly Magnitude Distributions(June 2018)')
plt.legend((p1[0], p2[0],p3[0],p4[0]),('M4_M4.5', 'M4.5_M5','M5_M5.8','M5.8_M6.5'))
# Show graphic
plt.show()
A file for solutioning to program;
You absolutely will evaluate that this program as base is on 3 layer stack concept...I explained 4 layer stack barchart.Thus,you will design to your multi-stack barchart on Project.
Yorumlar
Yorum Gönder