-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Selling-Pandas/plots_patterns
Plots_patterns
- Loading branch information
Showing
14 changed files
with
3,715 additions
and
1,117 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 |
---|---|---|
|
@@ -3,4 +3,6 @@ max-line-length = 89 | |
import-style-order = google | ||
inline-quotes = double | ||
|
||
ignore=T201 | ||
ignore= | ||
T201 | ||
exclude=test.py |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import matplotlib.pyplot as plt | ||
from matplotlib import font_manager | ||
from pandas import DataFrame | ||
from spandas.utils import is_float | ||
|
||
from typing import Tuple | ||
|
||
|
||
def subplots(nplots: int, figsize: Tuple[int, int] = ()): | ||
font_dirs = ['fonts'] | ||
font_files = font_manager.findSystemFonts(fontpaths=font_dirs) | ||
|
||
for font_file in font_files: | ||
font_manager.fontManager.addfont(font_file) | ||
|
||
plt.rcParams["font.family"] = "HSE Sans" | ||
plt.rcParams["font.size"] = 32 | ||
# сменить цвет графика на тёмнно-синий | ||
plt.rcParams["axes.prop_cycle"] = plt.cycler(color=["#01287a"]) | ||
n = (nplots // 2) + nplots % 2 | ||
if not figsize: | ||
figsize = (20, 10 * n) | ||
fig, axes = plt.subplots( | ||
nrows=n, | ||
ncols=2, | ||
figsize=figsize | ||
) | ||
return fig, axes | ||
|
||
|
||
def print_distributions( | ||
df: DataFrame, cols: dict, figsize: tuple[int, int] = (30, 30), bins: int = 100 | ||
) -> tuple[bool, str]: | ||
try: | ||
_, axes = subplots( | ||
len(cols), | ||
figsize=figsize, | ||
) | ||
i, j, max_i = ( | ||
0, | ||
0, | ||
(len(cols) // 2) + (1 if len(cols) % 2 > 0 else 0), | ||
) | ||
for col in cols: | ||
col_of_nums = df[col].apply( | ||
lambda x: (-1000 if (not is_float(str(x)) or x != x) else float(x)) | ||
) # x != x only when x is NaN | ||
axes[i, j].hist(col_of_nums) | ||
axes[i, j].set_xlabel(f"Значение переменной {col}") | ||
axes[i, j].set_ylabel("Частота") | ||
axes[i, j].set_title(f"График распределения переменной {col}") | ||
# axes[i, j].set_xticks(range()) | ||
# axes[i, j].set_xlim(min(-1000, col_of_nums.min()), col_of_nums.max()) | ||
# axes[i, j].set_ylim(0, 1500) | ||
i += 1 | ||
if i == max_i: | ||
j += 1 | ||
i = 0 | ||
plt.tight_layout() | ||
plt.show() | ||
except Exception as ex: | ||
return False, str(ex) | ||
return True, "" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def is_float(string): | ||
if string.replace(".", "").replace(',', '').isnumeric(): | ||
return True | ||
else: | ||
return False |
Oops, something went wrong.