Skip to content

Commit fbf525d

Browse files
authored
Merge pull request #166 from Swish78/dynamic-figsize-adjustment
Fix issue #30
2 parents ea466ad + 2b17541 commit fbf525d

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change Log
22

3+
## 0.7.8
4+
* `nominal.associations` now attempts to set the figure-size automatically based on output (issue [#30](https://github.com/shakedzy/dython/issues/30), by **[@Swish78](https://github.com/Swish78)**)
5+
36
## 0.7.7
47
* _Drop support for Python 3.8 as it reaches its end-of-life date_
58
* Fix issue [#160](https://github.com/shakedzy/dython/issues/160)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7.7
1+
0.7.8

dev_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pytest[testing]>=8.3.2
1+
pytest>=8.3.2
22
hypothesis>=6.111.0
33
black>=24.8.0
44
pre-commit>=3.8.0

docs/modules/nominal.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,12 @@ continuous features using:
161161

162162
Matplotlib Axis on which the heat-map will be plotted
163163

164-
- **`figsize`** : `(int,int)` or `None`
164+
- **`figsize`** : `(float, float)` or `None`
165165

166166
_Default: None_
167167

168-
A Matplotlib figure-size tuple. If `None`, falls back to Matplotlib's default. Only used if `ax=None`.
168+
A Matplotlib figure-size tuple. If `None`, will attempt to set the size automatically.
169+
Only used if `ax=None`.
169170

170171
- **`annot`** : `Boolean`
171172

dython/nominal.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def associations(
396396
nan_strategy: str = _REPLACE,
397397
nan_replace_value: Any = _DEFAULT_REPLACE_VALUE,
398398
ax: Optional[plt.Axes] = None,
399-
figsize: Optional[Tuple[int, int]] = None,
399+
figsize: Optional[Tuple[float, float]] = None,
400400
annot: bool = True,
401401
fmt: str = ".2f",
402402
cmap: Optional[Colormap] = None,
@@ -439,16 +439,16 @@ def associations(
439439
'(con)' based on their type (nominal or continuous), as provided
440440
by nominal_columns
441441
nom_nom_assoc : callable / string, default = 'cramer'
442-
If callable, a function which recieves two `pd.Series` and returns a single number.
442+
If callable, a function which receives two `pd.Series` and returns a single number.
443443
If string, name of nominal-nominal (categorical-categorical) association to use.
444444
Options are 'cramer' for Cramer's V or `theil` for Theil's U. If 'theil',
445445
heat-map columns are the provided information (U = U(row|col)).
446446
num_num_assoc : callable / string, default = 'pearson'
447-
If callable, a function which recieves two `pd.Series` and returns a single number.
447+
If callable, a function which receives two `pd.Series` and returns a single number.
448448
If string, name of numerical-numerical association to use. Options are 'pearson'
449449
for Pearson's R, 'spearman' for Spearman's R, 'kendall' for Kendall's Tau.
450450
nom_num_assoc : callable / string, default = 'correlation_ratio'
451-
If callable, a function which recieves two `pd.Series` and returns a single number.
451+
If callable, a function which receives two `pd.Series` and returns a single number.
452452
If string, name of nominal-numerical association to use. Options are 'correlation_ratio'
453453
for correlation ratio.
454454
symmetric_nom_nom : Boolean, default = True
@@ -458,19 +458,19 @@ def associations(
458458
Relevant only if `num_num_assoc` is a callable. Declare whether the function is symmetric (f(x,y) = f(y,x)).
459459
If False, heat-map values should be interpreted as f(row,col)
460460
display_rows : list / string, default = 'all'
461-
Choose which of the dataset's features will be displyed in the output's
461+
Choose which of the dataset's features will be displayed in the output's
462462
correlations table rows. If string, can either be a single feature's name or 'all'.
463463
Only used if `hide_rows` is `None`.
464464
display_columns : list / string, default = 'all'
465-
Choose which of the dataset's features will be displyed in the output's
465+
Choose which of the dataset's features will be displayed in the output's
466466
correlations table columns. If string, can either be a single feature's name or 'all'.
467467
Only used if `hide_columns` is `None`.
468468
hide_rows : list / string, default = None
469-
Choose which of the dataset's features will not be displyed in the output's
469+
Choose which of the dataset's features will not be displayed in the output's
470470
correlations table rows. If string, must be a single feature's name. If `None`,
471471
`display_rows` is used.
472472
hide_columns : list / string, default = None
473-
Choose which of the dataset's features will not be displyed in the output's
473+
Choose which of the dataset's features will not be displayed in the output's
474474
correlations table columns. If string, must be a single feature's name. If `None`,
475475
`display_columns` is used.
476476
cramers_v_bias_correction : Boolean, default = True
@@ -488,9 +488,9 @@ def associations(
488488
nan_strategy is set to 'replace'
489489
ax : matplotlib ax, default = None
490490
Matplotlib Axis on which the heat-map will be plotted
491-
figsize : (int,int) or None, default = None
492-
A Matplotlib figure-size tuple. If `None`, falls back to Matplotlib's
493-
default. Only used if `ax=None`.
491+
figsize : (float, float) or None, default = None
492+
A Matplotlib figure-size tuple. If `None`, will attempt to set the size automatically.
493+
Only used if `ax=None`.
494494
annot : Boolean, default = True
495495
Plot number annotations on the heat-map
496496
fmt : string, default = '.2f'
@@ -564,7 +564,7 @@ def associations(
564564
pass # will be handled pair-by-pair during calculations
565565
else:
566566
raise ValueError(
567-
"Argument nan_stragety [{:s}] is not a valid choice.".format(
567+
"Argument nan_strategy [{:s}] is not a valid choice.".format(
568568
nan_strategy
569569
)
570570
)
@@ -614,6 +614,12 @@ def associations(
614614
)
615615
displayed_features_set = set.union(set(display_rows), set(display_columns))
616616

617+
# Adjusting figsize based on the number of features
618+
if figsize is None:
619+
BASE_SIZE = 1.5 # Size multiplier per feature
620+
num_features = len(displayed_features_set)
621+
figsize = (BASE_SIZE * num_features, BASE_SIZE * num_features)
622+
617623
# convert timestamp columns to numerical columns, so correlation can be performed
618624
datetime_dtypes = [
619625
str(x) for x in df.dtypes if str(x).startswith("datetime64")

0 commit comments

Comments
 (0)