I am trying to plot the gini coefficient on a graph, showing different data for different variables (GDP_PPP and GDP_MER) to show the inequalities between gdp market exchange rate and gdp as gross national income. I am struggling to get both variables to appear on the same graph.
The below code is what I have done to calculate the Gini coefficient function:
def GiniCoeff_plot(pop, resource):
iuse = (np.logical_not(pop.isnull()) & np.logical_not(resource.isnull())) & np.greater(np.float64(resource),0)
pop = pop[iuse]; pop = np.array(np.float64(pop))
resource = resource[iuse]; resource = np.array(np.float64(resource))
resource = resource/pop
resource2 = resource2[iuse]; resource = np.array(np.float64(resource2))
resource2 = resource2/pop
pw = np.array([pop.tolist(), resource.tolist(), resource2.tolist()]); pw = pw.T
pw = pw[pw[:,1].argsort()]; (r, c) = pw.shape
pw2 = pw2[pw2[:,1].argsort()]; (r, c) = pw2.shape
fy = pw[:,0]/sum(pw[:,0])
F = np.zeros(r+1); S = np.zeros(r+1); L = np.zeros(r+1)
F[1:r+1] = np.cumsum(fy)
S[1:r+1] = np.cumsum(fy*pw[:,1])
S2[1:r+1] = np.cumsum(fy*pw[:,1])
L = S/S[-1]
L2 = S2/S2[-1]
partarea1 = np.sum(fy.T * L[0:r])
partarea2 = np.sum(fy.T * L[1:r+1])
G = 1 - partarea1 - partarea2
#ploting data
plotflag=1
if plotflag==1:
plt.plot(F, L, '-b', label="observed")
plt.plot(F, F, '--k', label="perfect eq.")
plt.plot(F, L2, '-y', label='test')
plt.xlabel("Population")
plt.xticks(np.arange(0,1.1, step=0.1), ["{}%".format(i) for i in range(0,110,10)])
plt.ylabel("Resources")
plt.yticks(np.arange(0,1.1, step=0.1), ["{}%".format(i) for i in range(0,110,10)])
plt.grid(color='k', linestyle='-', linewidth=0.1)
plt.title("GINI: %.4f" %(G))
plt.legend()
plt.show()
return G
and:
pop = pd.DataFrame(C04["pop"]); pop = pop[pop.applymap(isnumber)]; pop=pop["pop"]
resource = pd.DataFrame(C04["gdp_mer"]); resource = resource[resource.applymap(isnumber)]; resource = resource["gdp_mer"]
resource2 = pd.DataFrame(C04["gdp_ppp"]); resource2 = resource2[resource2.applymap(isnumber)]; resource2= resource2["gdp_ppp"]
G = GiniCoeff_plot(pop, resource, resource2)
print("G = {:.4f}".format(G))
however I keep getting the error: "TypeError: GiniCoeff_plot()
takes 2 positional arguments but 3 were given"
Does anyone know how I can change it so that I can include the two variables? Any help would be greatly appreciated!