-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
factored that pie charts size reflect change in area
- Loading branch information
Sven Eggimann
committed
Apr 24, 2019
1 parent
3f7ece1
commit cf2da51
Showing
3 changed files
with
170 additions
and
77 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,27 @@ | ||
import pandas as pd | ||
import numpy as np | ||
import math | ||
import matplotlib.pyplot as plt | ||
|
||
# Dataset | ||
dataright = np.random.rand(10, 4) | ||
dataleft = dataright * -1 | ||
df_right = pd.DataFrame(dataright, columns=['a', 'b', 'c', 'd']) | ||
df_left = pd.DataFrame(dataleft, columns=['a', 'b', 'c', 'd']) | ||
|
||
# Some data | ||
fracs = [15, 30, 45, 10] | ||
|
||
# plot WORKDS | ||
#labels_minus = list(df_left.values) | ||
#labels_plus = list(df_right.values) | ||
#labels = labels_minus + labels_plus | ||
# Make figure and axes | ||
fig, axs = plt.subplots(2,2) | ||
|
||
''' | ||
df_right.plot(kind='barh', stacked=True, width=1.0) | ||
df_left.plot(kind='barh',stacked=True, width=1.0)''' | ||
|
||
|
||
fig, ax = plt.subplots(ncols=1, sharey=True) | ||
standard_area_to_define_radius = 4 | ||
|
||
##ax.invert_xaxis() | ||
##ax.yaxis.tick_right() | ||
#ax.set_yticklabels(labels) | ||
# Add vertical line | ||
ax.axvline(linewidth=1, color='black') | ||
old_area = 1 | ||
new_area = 2 | ||
|
||
df_right.plot(kind='barh', legend=True, ax=ax, width=1.0, stacked=True) | ||
df_left.plot(kind='barh', legend=True, ax=ax, width=1.0, stacked=True) | ||
plt.show() | ||
area_change = new_area / old_area | ||
|
||
#raise Exception | ||
old_radius = (1 / standard_area_to_define_radius) * old_area | ||
|
||
#https://stackoverflow.com/questions/44049132/python-pandas-plotting-two-barh-side-by-side | ||
#df = pd.DataFrame() | ||
#new_radius = math.sqrt(area_change * new_area / math.pi) | ||
new_radius = math.sqrt(area_change) * old_radius | ||
|
||
#df_1[target_cols].plot(kind='barh', x='LABEL', stacked=True, legend=False) | ||
#df_2[target_cols].plot(kind='barh', x='LABEL', stacked=True).invert_xaxis() | ||
axs[1,0].pie(fracs, radius=old_radius) | ||
axs[1,1].pie(fracs, radius=new_radius) | ||
|
||
#x_axis = [list(df_right.index)] | ||
#print(x_axis) | ||
#print("...") | ||
#print(np.array([5., 30., 45., 22.])) | ||
##plt.barh(np.arange(4), np.array([5., 30., 45., 22.]), color = 'r') | ||
#plt.barh(x_axis, df_right, color = 'r', stacked='True') | ||
#plt.barh(x_axis, df_right, color='r', stacked=True) | ||
#plt.barh(x_axis, df_left, color='b', stacked=True) | ||
|
||
#plt.show()# | ||
#print("..") | ||
|
||
''' | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
women_pop = np.array([5., 30., 45., 22.]) | ||
men_pop = np.array( [5., 25., 50., 20.]) | ||
X = np.arange(4) | ||
plt.barh(X, women_pop, color = 'r') | ||
plt.barh(X, -men_pop, color = 'b') | ||
plt.show() | ||
''' | ||
plt.show() |
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 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