Skip to content

Commit

Permalink
Merge pull request #43 from cmmorrow/FEATURE-Reduce_figure_size
Browse files Browse the repository at this point in the history
Reduced figure size
  • Loading branch information
cmmorrow committed Mar 30, 2019
2 parents 8fdd1c3 + 582da6f commit 86db076
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
4 changes: 2 additions & 2 deletions sci_analysis/graphs/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def draw(self):

class GraphFrequency(CategoricalGraph):

_xsize = 9
_ysize = 6
_xsize = 8.5
_ysize = 5.5

def __init__(self, data, **kwargs):

Expand Down
36 changes: 19 additions & 17 deletions sci_analysis/graphs/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class GraphHisto(VectorGraph):
box plot.
"""

_xsize = 7
_ysize = 6
_xsize = 5
_ysize = 4

def __init__(self, data, **kwargs):
"""GraphHisto constructor.
Expand Down Expand Up @@ -155,11 +155,11 @@ def draw(self):
h_ratios = [histo_span]
p = []
if self._box_plot:
self._ysize += 1
self._ysize += 0.5
self._nrows += 1
h_ratios.insert(0, box_plot_span)
if self._cdf:
self._ysize += 4
self._ysize += 2
self._nrows += 1
h_ratios.insert(0, cdf_span)

Expand Down Expand Up @@ -255,8 +255,8 @@ class GraphScatter(VectorGraph):

_nrows = 1
_ncols = 1
_xsize = 8
_ysize = 7
_xsize = 6
_ysize = 5

def __init__(self, xdata, ydata=None, **kwargs):
"""GraphScatter constructor.
Expand Down Expand Up @@ -356,8 +356,9 @@ def draw(self):
# Setup the figure and gridspec
if self._boxplot_borders:
self._nrows, self._ncols = 2, 2
self._xsize, self._ysize = 8.5, 7.5
h_ratio, w_ratio = (2, 5), (5, 2)
self._xsize = self._xsize + 0.5
self._ysize = self._ysize + 0.5
h_ratio, w_ratio = (1.5, 5.5), (5.5, 1.5)
main_plot = 2
else:
main_plot = 0
Expand Down Expand Up @@ -402,7 +403,7 @@ def draw(self):
if self._points:
# A 2-D array needs to be passed to prevent matplotlib from applying the default cmap if the size < 4.
color = (self.get_color(0),)
alpha_trans = 0.8
alpha_trans = 0.7
if self._highlight is not None:
# Find index of the labels which are in the highlight list
labelmask = self._data.labels.isin(self._highlight)
Expand All @@ -412,7 +413,7 @@ def draw(self):
y_labels = y.loc[labelmask]
x_nolabels = x.loc[~labelmask]
y_nolabels = y.loc[~labelmask]
ax2.scatter(x_labels, y_labels, c=color, marker='o', linewidths=0, alpha=.8, zorder=1)
ax2.scatter(x_labels, y_labels, c=color, marker='o', linewidths=0, alpha=alpha_trans, zorder=1)
ax2.scatter(x_nolabels, y_nolabels, c=color, marker='o', linewidths=0, alpha=.2, zorder=1)
for k in self._data.labels[labelmask].index:
ax2.annotate(self._data.labels[k], xy=(x[k], y[k]), alpha=1, color=color[0])
Expand Down Expand Up @@ -457,8 +458,8 @@ class GraphGroupScatter(VectorGraph):

_nrows = 1
_ncols = 1
_xsize = 8
_ysize = 7
_xsize = 6
_ysize = 5

def __init__(self, xdata, ydata=None, groups=None, **kwargs):
"""GraphScatter constructor.
Expand Down Expand Up @@ -533,8 +534,9 @@ def draw(self):
# Setup the figure and gridspec
if self._boxplot_borders:
self._nrows, self._ncols = 2, 2
self._xsize, self._ysize = 8.5, 7.5
h_ratio, w_ratio = (2, 5), (5, 2)
self._xsize = self._xsize + 0.5
self._ysize = self._ysize + 0.5
h_ratio, w_ratio = (1.5, 5.5), (5.5, 1.5)
main_plot = 2
else:
main_plot = 0
Expand Down Expand Up @@ -683,8 +685,8 @@ class GraphBoxplot(VectorGraph):

_nrows = 1
_ncols = 1
_xsize = 7.5
_ysize = 6
_xsize = 5.75
_ysize = 5
_default_alpha = 0.05

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -810,7 +812,7 @@ def draw(self):
ax1.axhline(float(self.grand_mean(data)), c='k', linestyle='--', alpha=0.4)
if self._gmedian:
ax1.axhline(float(self.grand_median(data)), c='k', linestyle=':', alpha=0.4)
if any([True if len(str(g)) > 10 else False for g in groups]) or len(groups) > 5:
if any([True if len(str(g)) > 9 else False for g in groups]) or len(groups) > 5:
xticks(rotation=60)
subplots_adjust(bottom=0.2)
ylabel(self._yname)
Expand Down
15 changes: 14 additions & 1 deletion sci_analysis/test/test_graph_boxplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def test_133_boxplot_horizontal_labels_length_size(self):
input_5_array = st.norm.rvs(size=100)
self.assertTrue(GraphBoxplot(input_1_array, input_2_array, input_3_array, input_4_array, input_5_array,
title='Horizontal labels test',
groups=['1111111111', '2222222222', '3333333333', '4444444444', '5555555555'],
groups=['111111111', '222222222', '333333333', '444444444', '555555555'],
save_to='{}test_box_133'.format(self.save_path)))

def test_134_boxplot_vertical_labels_length(self):
Expand Down Expand Up @@ -613,6 +613,19 @@ def test_151_no_gmedian_or_gmean(self):
save_to='{}test_box_151'.format(self.save_path))
self.assertTrue(res)

def test_152_boxplot_2_no_nqp_no_circles(self):
"""Generate a boxplot graph with no nqp and no circles."""
np.random.seed(self._seed)
input_1_array = st.norm.rvs(size=2000)
input_2_array = st.norm.rvs(1, size=2000)
self.assertWarnsCrossCompatible(FutureWarning,
lambda: GraphBoxplot(input_1_array,
input_2_array,
nqp=False,
circles=False,
save_to='{}test_box_152'.format(self.save_path)),
message='multiple arguments')


if __name__ == '__main__':
unittest.main()

0 comments on commit 86db076

Please sign in to comment.