AeroViz 0.1.3__py3-none-any.whl → 0.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of AeroViz might be problematic. Click here for more details.
- AeroViz/__init__.py +7 -5
- AeroViz/{config → data}/DEFAULT_DATA.csv +1 -1
- AeroViz/dataProcess/Chemistry/__init__.py +40 -40
- AeroViz/dataProcess/Chemistry/_calculate.py +15 -15
- AeroViz/dataProcess/Chemistry/_isoropia.py +72 -68
- AeroViz/dataProcess/Chemistry/_mass_volume.py +158 -161
- AeroViz/dataProcess/Chemistry/_ocec.py +109 -109
- AeroViz/dataProcess/Chemistry/_partition.py +19 -18
- AeroViz/dataProcess/Chemistry/_teom.py +9 -11
- AeroViz/dataProcess/Chemistry/isrpia.cnf +21 -0
- AeroViz/dataProcess/Optical/Angstrom_exponent.py +20 -0
- AeroViz/dataProcess/Optical/_IMPROVE.py +40 -41
- AeroViz/dataProcess/Optical/__init__.py +29 -44
- AeroViz/dataProcess/Optical/_absorption.py +21 -47
- AeroViz/dataProcess/Optical/_extinction.py +31 -25
- AeroViz/dataProcess/Optical/_mie.py +5 -7
- AeroViz/dataProcess/Optical/_mie_sd.py +89 -90
- AeroViz/dataProcess/Optical/_scattering.py +19 -20
- AeroViz/dataProcess/SizeDistr/__init__.py +39 -39
- AeroViz/dataProcess/SizeDistr/__merge.py +159 -158
- AeroViz/dataProcess/SizeDistr/_merge.py +155 -154
- AeroViz/dataProcess/SizeDistr/_merge_v1.py +162 -161
- AeroViz/dataProcess/SizeDistr/_merge_v2.py +153 -152
- AeroViz/dataProcess/SizeDistr/_merge_v3.py +327 -327
- AeroViz/dataProcess/SizeDistr/_merge_v4.py +273 -275
- AeroViz/dataProcess/SizeDistr/_size_distr.py +51 -51
- AeroViz/dataProcess/VOC/__init__.py +9 -9
- AeroViz/dataProcess/VOC/_potential_par.py +53 -55
- AeroViz/dataProcess/__init__.py +28 -6
- AeroViz/dataProcess/core/__init__.py +59 -65
- AeroViz/plot/__init__.py +7 -2
- AeroViz/plot/bar.py +126 -0
- AeroViz/plot/box.py +69 -0
- AeroViz/plot/distribution/distribution.py +421 -427
- AeroViz/plot/meteorology/meteorology.py +240 -292
- AeroViz/plot/optical/__init__.py +0 -1
- AeroViz/plot/optical/optical.py +230 -230
- AeroViz/plot/pie.py +198 -0
- AeroViz/plot/regression.py +196 -0
- AeroViz/plot/scatter.py +165 -0
- AeroViz/plot/templates/__init__.py +2 -4
- AeroViz/plot/templates/ammonium_rich.py +34 -0
- AeroViz/plot/templates/contour.py +25 -25
- AeroViz/plot/templates/corr_matrix.py +86 -93
- AeroViz/plot/templates/diurnal_pattern.py +28 -26
- AeroViz/plot/templates/koschmieder.py +59 -123
- AeroViz/plot/templates/metal_heatmap.py +135 -37
- AeroViz/plot/timeseries/__init__.py +1 -0
- AeroViz/plot/timeseries/template.py +47 -0
- AeroViz/plot/timeseries/timeseries.py +324 -264
- AeroViz/plot/utils/__init__.py +2 -1
- AeroViz/plot/utils/_color.py +57 -57
- AeroViz/plot/utils/_unit.py +48 -48
- AeroViz/plot/utils/plt_utils.py +92 -0
- AeroViz/plot/utils/sklearn_utils.py +49 -0
- AeroViz/plot/utils/units.json +5 -0
- AeroViz/plot/violin.py +80 -0
- AeroViz/process/__init__.py +17 -17
- AeroViz/process/core/DataProc.py +9 -9
- AeroViz/process/core/SizeDist.py +81 -81
- AeroViz/process/method/PyMieScatt_update.py +488 -488
- AeroViz/process/method/mie_theory.py +231 -229
- AeroViz/process/method/prop.py +40 -40
- AeroViz/process/script/AbstractDistCalc.py +103 -103
- AeroViz/process/script/Chemical.py +168 -167
- AeroViz/process/script/IMPACT.py +40 -40
- AeroViz/process/script/IMPROVE.py +152 -152
- AeroViz/process/script/Others.py +45 -45
- AeroViz/process/script/PSD.py +26 -26
- AeroViz/process/script/PSD_dry.py +69 -70
- AeroViz/process/script/retrieve_RI.py +50 -51
- AeroViz/rawDataReader/__init__.py +53 -58
- AeroViz/rawDataReader/config/supported_instruments.py +155 -0
- AeroViz/rawDataReader/core/__init__.py +233 -356
- AeroViz/rawDataReader/script/AE33.py +17 -18
- AeroViz/rawDataReader/script/AE43.py +18 -21
- AeroViz/rawDataReader/script/APS_3321.py +30 -30
- AeroViz/rawDataReader/script/Aurora.py +23 -24
- AeroViz/rawDataReader/script/BC1054.py +36 -40
- AeroViz/rawDataReader/script/EPA_vertical.py +37 -9
- AeroViz/rawDataReader/script/GRIMM.py +16 -23
- AeroViz/rawDataReader/script/IGAC.py +90 -0
- AeroViz/rawDataReader/script/MA350.py +32 -39
- AeroViz/rawDataReader/script/Minion.py +103 -0
- AeroViz/rawDataReader/script/NEPH.py +69 -74
- AeroViz/rawDataReader/script/SMPS_TH.py +25 -25
- AeroViz/rawDataReader/script/SMPS_aim11.py +32 -32
- AeroViz/rawDataReader/script/SMPS_genr.py +31 -31
- AeroViz/rawDataReader/script/Sunset_OCEC.py +60 -0
- AeroViz/rawDataReader/script/TEOM.py +30 -28
- AeroViz/rawDataReader/script/Table.py +13 -14
- AeroViz/rawDataReader/script/VOC.py +26 -0
- AeroViz/rawDataReader/script/__init__.py +18 -20
- AeroViz/tools/database.py +64 -66
- AeroViz/tools/dataclassifier.py +106 -106
- AeroViz/tools/dataprinter.py +51 -51
- AeroViz/tools/datareader.py +38 -38
- {AeroViz-0.1.3.dist-info → AeroViz-0.1.4.dist-info}/METADATA +5 -4
- AeroViz-0.1.4.dist-info/RECORD +112 -0
- AeroViz/plot/improve/__init__.py +0 -1
- AeroViz/plot/improve/improve.py +0 -240
- AeroViz/plot/optical/aethalometer.py +0 -77
- AeroViz/plot/templates/event_evolution.py +0 -65
- AeroViz/plot/templates/regression.py +0 -256
- AeroViz/plot/templates/scatter.py +0 -130
- AeroViz/plot/templates/templates.py +0 -398
- AeroViz/plot/utils/_decorator.py +0 -74
- AeroViz/rawDataReader/script/IGAC_TH.py +0 -104
- AeroViz/rawDataReader/script/IGAC_ZM.py +0 -90
- AeroViz/rawDataReader/script/OCEC_LCRES.py +0 -34
- AeroViz/rawDataReader/script/OCEC_RES.py +0 -28
- AeroViz/rawDataReader/script/VOC_TH.py +0 -30
- AeroViz/rawDataReader/script/VOC_ZM.py +0 -37
- AeroViz/rawDataReader/utils/__init__.py +0 -0
- AeroViz/rawDataReader/utils/config.py +0 -169
- AeroViz-0.1.3.dist-info/RECORD +0 -111
- /AeroViz/{config → data}/DEFAULT_PNSD_DATA.csv +0 -0
- /AeroViz/{config → rawDataReader/config}/__init__.py +0 -0
- {AeroViz-0.1.3.dist-info → AeroViz-0.1.4.dist-info}/LICENSE +0 -0
- {AeroViz-0.1.3.dist-info → AeroViz-0.1.4.dist-info}/WHEEL +0 -0
- {AeroViz-0.1.3.dist-info → AeroViz-0.1.4.dist-info}/top_level.txt +0 -0
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import matplotlib.pyplot as plt
|
|
2
|
-
import numpy as np
|
|
3
|
-
import pandas as pd
|
|
4
|
-
from matplotlib.pyplot import Figure, Axes
|
|
5
|
-
from sklearn.linear_model import LinearRegression
|
|
6
|
-
from tabulate import tabulate
|
|
7
|
-
|
|
8
|
-
from AeroViz.plot.utils import *
|
|
9
|
-
|
|
10
|
-
__all__ = [
|
|
11
|
-
'linear_regression',
|
|
12
|
-
'multiple_linear_regression',
|
|
13
|
-
]
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def _linear_regression(x_array: np.ndarray,
|
|
17
|
-
y_array: np.ndarray,
|
|
18
|
-
columns: str | list[str] | None = None,
|
|
19
|
-
positive: bool = True,
|
|
20
|
-
fit_intercept: bool = True):
|
|
21
|
-
if len(x_array.shape) > 1 and x_array.shape[1] >= 2:
|
|
22
|
-
model = LinearRegression(positive=positive, fit_intercept=fit_intercept).fit(x_array, y_array)
|
|
23
|
-
|
|
24
|
-
coefficients = model.coef_[0].round(3)
|
|
25
|
-
intercept = model.intercept_[0].round(3) if fit_intercept else 'None'
|
|
26
|
-
r_square = model.score(x_array, y_array).round(3)
|
|
27
|
-
y_predict = model.predict(x_array)
|
|
28
|
-
|
|
29
|
-
equation = ' + '.join([f'{coeff:.3f} * {col}' for coeff, col in zip(coefficients, columns)])
|
|
30
|
-
equation = equation.replace(' + 0.000 * Const', '') # Remove terms with coefficient 0
|
|
31
|
-
|
|
32
|
-
text = 'y = ' + str(equation) + '\n' + r'$\bf R^2 = $' + str(r_square)
|
|
33
|
-
tab = tabulate([[*coefficients, intercept, r_square]], headers=[*columns, 'intercept', 'R^2'], floatfmt=".3f",
|
|
34
|
-
tablefmt="fancy_grid")
|
|
35
|
-
print('\n' + tab)
|
|
36
|
-
|
|
37
|
-
return text, y_predict, coefficients
|
|
38
|
-
|
|
39
|
-
else:
|
|
40
|
-
x_array = x_array.reshape(-1, 1)
|
|
41
|
-
y_array = y_array.reshape(-1, 1)
|
|
42
|
-
|
|
43
|
-
model = LinearRegression(positive=positive, fit_intercept=fit_intercept).fit(x_array, y_array)
|
|
44
|
-
|
|
45
|
-
slope = model.coef_[0][0].round(3)
|
|
46
|
-
intercept = model.intercept_[0].round(3) if fit_intercept else 'None'
|
|
47
|
-
r_square = model.score(x_array, y_array).round(3)
|
|
48
|
-
y_predict = model.predict(x_array)
|
|
49
|
-
|
|
50
|
-
text = np.poly1d([slope, intercept])
|
|
51
|
-
text = 'y = ' + str(text).replace('\n', "") + '\n' + r'$\bf R^2 = $' + str(r_square)
|
|
52
|
-
|
|
53
|
-
tab = tabulate([[slope, intercept, r_square]], headers=['slope', 'intercept', 'R^2'], floatfmt=".3f",
|
|
54
|
-
tablefmt="fancy_grid")
|
|
55
|
-
print('\n' + tab)
|
|
56
|
-
|
|
57
|
-
return text, y_predict, slope
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
@set_figure
|
|
61
|
-
def linear_regression(df: pd.DataFrame,
|
|
62
|
-
x: str | list[str],
|
|
63
|
-
y: str | list[str],
|
|
64
|
-
labels: str | list[str] = None,
|
|
65
|
-
ax: Axes | None = None,
|
|
66
|
-
diagonal=False,
|
|
67
|
-
positive: bool = True,
|
|
68
|
-
fit_intercept: bool = True,
|
|
69
|
-
**kwargs
|
|
70
|
-
) -> tuple[Figure, Axes]:
|
|
71
|
-
"""
|
|
72
|
-
Create a scatter plot with multiple regression lines for the given data.
|
|
73
|
-
|
|
74
|
-
Parameters
|
|
75
|
-
----------
|
|
76
|
-
df : DataFrame
|
|
77
|
-
Input DataFrame containing the data.
|
|
78
|
-
|
|
79
|
-
x : str or list of str
|
|
80
|
-
Column name(s) for the x-axis variable(s).
|
|
81
|
-
|
|
82
|
-
y : str or list of str
|
|
83
|
-
Column name(s) for the y-axis variable(s).
|
|
84
|
-
|
|
85
|
-
labels : str or list of str, optional
|
|
86
|
-
Labels for the y-axis variable(s). If None, column names are used as labels. Default is None.
|
|
87
|
-
|
|
88
|
-
ax : AxesSubplot, optional
|
|
89
|
-
Matplotlib AxesSubplot to use for the plot. If None, a new subplot is created. Default is None.
|
|
90
|
-
|
|
91
|
-
diagonal : bool, optional
|
|
92
|
-
If True, a diagonal line (1:1 line) is added to the plot. Default is False.
|
|
93
|
-
|
|
94
|
-
positive : bool, optional
|
|
95
|
-
Whether to let coefficient positive. Default is True.
|
|
96
|
-
|
|
97
|
-
fit_intercept: bool, optional
|
|
98
|
-
Whether to fit intercept. Default is True.
|
|
99
|
-
|
|
100
|
-
**kwargs
|
|
101
|
-
Additional keyword arguments to customize the plot.
|
|
102
|
-
|
|
103
|
-
Returns
|
|
104
|
-
-------
|
|
105
|
-
AxesSubplot
|
|
106
|
-
Matplotlib AxesSubplot containing the scatter plot.
|
|
107
|
-
|
|
108
|
-
Notes
|
|
109
|
-
-----
|
|
110
|
-
- The function creates a scatter plot with the option to include multiple regression lines.
|
|
111
|
-
- If regression is True, regression lines are fitted for each y variable.
|
|
112
|
-
- Additional customization can be done using the **kwargs.
|
|
113
|
-
|
|
114
|
-
Example
|
|
115
|
-
-------
|
|
116
|
-
>>> linear_regression(df, x='X', y=['Y1', 'Y2'], labels=['Label1', 'Label2'],
|
|
117
|
-
... regression=True, diagonal=True, xlim=(0, 10), ylim=(0, 20),
|
|
118
|
-
... xlabel="X-axis", ylabel="Y-axis", title="Scatter Plot with Regressions")
|
|
119
|
-
"""
|
|
120
|
-
fig, ax = plt.subplots(**kwargs.get('fig_kws', {})) if ax is None else (ax.get_figure(), ax)
|
|
121
|
-
|
|
122
|
-
if not isinstance(x, str):
|
|
123
|
-
x = x[0]
|
|
124
|
-
|
|
125
|
-
if not isinstance(y, list):
|
|
126
|
-
y = [y]
|
|
127
|
-
|
|
128
|
-
if labels is None:
|
|
129
|
-
labels = y
|
|
130
|
-
|
|
131
|
-
df = df.dropna(subset=[x, *y])
|
|
132
|
-
x_array = df[[x]].to_numpy()
|
|
133
|
-
|
|
134
|
-
color_cycle = Color.linecolor
|
|
135
|
-
|
|
136
|
-
handles, text_list = [], []
|
|
137
|
-
|
|
138
|
-
for i, y_var in enumerate(y):
|
|
139
|
-
y_array = df[[y_var]].to_numpy()
|
|
140
|
-
|
|
141
|
-
color = color_cycle[i % len(color_cycle)]
|
|
142
|
-
|
|
143
|
-
scatter = ax.scatter(x_array, y_array, s=25, color=color['face'], edgecolors=color['edge'], alpha=0.8,
|
|
144
|
-
label=labels[i])
|
|
145
|
-
handles.append(scatter)
|
|
146
|
-
|
|
147
|
-
text, y_predict, slope = _linear_regression(x_array, y_array,
|
|
148
|
-
columns=labels[i],
|
|
149
|
-
positive=positive,
|
|
150
|
-
fit_intercept=fit_intercept)
|
|
151
|
-
|
|
152
|
-
text_list.append(f'{labels[i]}: {text}')
|
|
153
|
-
plt.plot(x_array, y_predict, linewidth=3, color=color['line'], alpha=1, zorder=3)
|
|
154
|
-
|
|
155
|
-
ax.set(xlim=kwargs.get('xlim'), ylim=kwargs.get('ylim'), xlabel=Unit(x), ylabel=Unit(y[0]),
|
|
156
|
-
title=kwargs.get('title'))
|
|
157
|
-
|
|
158
|
-
# Add regression info to the legend
|
|
159
|
-
leg = plt.legend(handles=handles, labels=text_list, loc='upper left', prop={'weight': 'bold', 'size': 10})
|
|
160
|
-
|
|
161
|
-
for text, color in zip(leg.get_texts(), [color['line'] for color in color_cycle]):
|
|
162
|
-
text.set_color(color)
|
|
163
|
-
|
|
164
|
-
if diagonal:
|
|
165
|
-
ax.axline((0, 0), slope=1., color='k', lw=2, ls='--', alpha=0.5, label='1:1')
|
|
166
|
-
plt.text(0.97, 0.97, r'$\bf 1:1\ Line$', color='k', ha='right', va='top', transform=ax.transAxes)
|
|
167
|
-
|
|
168
|
-
plt.show()
|
|
169
|
-
|
|
170
|
-
return fig, ax
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
@set_figure
|
|
174
|
-
def multiple_linear_regression(df: pd.DataFrame,
|
|
175
|
-
x: str | list[str],
|
|
176
|
-
y: str | list[str],
|
|
177
|
-
labels: str | list[str] = None,
|
|
178
|
-
ax: Axes | None = None,
|
|
179
|
-
diagonal=False,
|
|
180
|
-
positive: bool = True,
|
|
181
|
-
fit_intercept: bool = True,
|
|
182
|
-
**kwargs
|
|
183
|
-
) -> tuple[Figure, Axes]:
|
|
184
|
-
"""
|
|
185
|
-
Perform multiple linear regression analysis and plot the results.
|
|
186
|
-
|
|
187
|
-
Parameters
|
|
188
|
-
----------
|
|
189
|
-
df : pandas.DataFrame
|
|
190
|
-
Input DataFrame containing the data.
|
|
191
|
-
|
|
192
|
-
x : str or list of str
|
|
193
|
-
Column name(s) for the independent variable(s). Can be a single string or a list of strings.
|
|
194
|
-
|
|
195
|
-
y : str or list of str
|
|
196
|
-
Column name(s) for the dependent variable(s). Can be a single string or a list of strings.
|
|
197
|
-
|
|
198
|
-
labels : str or list of str, optional
|
|
199
|
-
Labels for the dependent variable(s). If None, column names are used as labels. Default is None.
|
|
200
|
-
|
|
201
|
-
ax : matplotlib.axes.Axes or None, optional
|
|
202
|
-
Matplotlib Axes object to use for the plot. If None, a new subplot is created. Default is None.
|
|
203
|
-
|
|
204
|
-
diagonal : bool, optional
|
|
205
|
-
Whether to include a diagonal line (1:1 line) in the plot. Default is False.
|
|
206
|
-
|
|
207
|
-
positive : bool, optional
|
|
208
|
-
Whether to let coefficient positive. Default is True.
|
|
209
|
-
|
|
210
|
-
fit_intercept: bool, optional
|
|
211
|
-
Whether to fit intercept. Default is True.
|
|
212
|
-
|
|
213
|
-
**kwargs
|
|
214
|
-
Additional keyword arguments to customize the plot.
|
|
215
|
-
|
|
216
|
-
Returns
|
|
217
|
-
-------
|
|
218
|
-
matplotlib.axes.Axes
|
|
219
|
-
Matplotlib Axes object containing the regression plot.
|
|
220
|
-
|
|
221
|
-
Notes
|
|
222
|
-
-----
|
|
223
|
-
This function performs multiple linear regression analysis using the input DataFrame.
|
|
224
|
-
It supports multiple independent variables and can plot the regression results.
|
|
225
|
-
|
|
226
|
-
Example
|
|
227
|
-
-------
|
|
228
|
-
>>> multiple_linear_regression(df, x=['X1', 'X2'], y='Y', labels=['Y1', 'Y2'],
|
|
229
|
-
... diagonal=True, add_constant=True,
|
|
230
|
-
... xlabel="X-axis", ylabel="Y-axis", title="Multiple Linear Regression Plot")
|
|
231
|
-
"""
|
|
232
|
-
fig, ax = plt.subplots(**kwargs.get('fig_kws', {})) if ax is None else (ax.get_figure(), ax)
|
|
233
|
-
|
|
234
|
-
if not isinstance(x, list):
|
|
235
|
-
x = [x]
|
|
236
|
-
|
|
237
|
-
if not isinstance(y, str):
|
|
238
|
-
y = y[0]
|
|
239
|
-
|
|
240
|
-
if labels is None:
|
|
241
|
-
labels = x
|
|
242
|
-
|
|
243
|
-
df = df[[*x, y]].dropna()
|
|
244
|
-
x_array = df[[*x]].to_numpy()
|
|
245
|
-
y_array = df[[y]].to_numpy()
|
|
246
|
-
|
|
247
|
-
text, y_predict, coefficients = _linear_regression(x_array, y_array,
|
|
248
|
-
columns=labels,
|
|
249
|
-
positive=positive,
|
|
250
|
-
fit_intercept=fit_intercept)
|
|
251
|
-
|
|
252
|
-
df = pd.DataFrame(np.concatenate([y_array, y_predict], axis=1), columns=['y_actual', 'y_predict'])
|
|
253
|
-
|
|
254
|
-
linear_regression(df, x='y_actual', y='y_predict', ax=ax, regression=True, diagonal=diagonal)
|
|
255
|
-
|
|
256
|
-
return fig, ax
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import matplotlib.pyplot as plt
|
|
2
|
-
import numpy as np
|
|
3
|
-
import pandas as pd
|
|
4
|
-
import seaborn as sns
|
|
5
|
-
from matplotlib.colors import Normalize
|
|
6
|
-
from matplotlib.pyplot import Figure, Axes
|
|
7
|
-
from matplotlib.ticker import ScalarFormatter
|
|
8
|
-
|
|
9
|
-
from AeroViz.plot.templates.regression import _linear_regression
|
|
10
|
-
from AeroViz.plot.utils import *
|
|
11
|
-
|
|
12
|
-
__all__ = ['scatter']
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@set_figure
|
|
16
|
-
def scatter(df: pd.DataFrame,
|
|
17
|
-
x: str,
|
|
18
|
-
y: str,
|
|
19
|
-
c: str | None = None,
|
|
20
|
-
s: str | None = None,
|
|
21
|
-
cmap='jet',
|
|
22
|
-
regression=False,
|
|
23
|
-
diagonal=False,
|
|
24
|
-
box=False,
|
|
25
|
-
ax: Axes | None = None,
|
|
26
|
-
**kwargs) -> tuple[Figure, Axes]:
|
|
27
|
-
fig, ax = plt.subplots(**kwargs.get('fig_kws', {})) if ax is None else (ax.get_figure(), ax)
|
|
28
|
-
|
|
29
|
-
if c is not None and s is not None:
|
|
30
|
-
df_ = df.dropna(subset=[x, y, c, s]).copy()
|
|
31
|
-
x_data, y_data, c_data, s_data = df_[x].to_numpy(), df_[y].to_numpy(), df_[c].to_numpy(), df_[s].to_numpy()
|
|
32
|
-
|
|
33
|
-
scatter = ax.scatter(x_data, y_data, c=c_data,
|
|
34
|
-
norm=Normalize(vmin=np.percentile(c_data, 10), vmax=np.percentile(c_data, 90)),
|
|
35
|
-
cmap=cmap, s=50 * (s_data / s_data.max()) ** 1.5, alpha=0.7, edgecolors=None)
|
|
36
|
-
colorbar = True
|
|
37
|
-
|
|
38
|
-
dot = np.linspace(s_data.min(), s_data.max(), 6).round(-1)
|
|
39
|
-
|
|
40
|
-
for dott in dot[1:-1]:
|
|
41
|
-
plt.scatter([], [], c='k', alpha=0.8, s=50 * (dott / s_data.max()) ** 1.5, label='{:.0f}'.format(dott))
|
|
42
|
-
|
|
43
|
-
plt.legend(title=Unit(s))
|
|
44
|
-
|
|
45
|
-
elif c is not None:
|
|
46
|
-
df_ = df.dropna(subset=[x, y, c]).copy()
|
|
47
|
-
x_data, y_data, c_data = df_[x].to_numpy(), df_[y].to_numpy(), df_[c].to_numpy()
|
|
48
|
-
|
|
49
|
-
scatter = ax.scatter(x_data, y_data, c=c_data, vmin=c_data.min(), vmax=np.percentile(c_data, 90), cmap=cmap,
|
|
50
|
-
alpha=0.7,
|
|
51
|
-
edgecolors=None)
|
|
52
|
-
colorbar = True
|
|
53
|
-
|
|
54
|
-
elif s is not None:
|
|
55
|
-
df_ = df.dropna(subset=[x, y, s]).copy()
|
|
56
|
-
x_data, y_data, s_data = df_[x].to_numpy(), df_[y].to_numpy(), df_[s].to_numpy()
|
|
57
|
-
|
|
58
|
-
scatter = ax.scatter(x_data, y_data, s=50 * (s_data / s_data.max()) ** 1.5, color='#7a97c9', alpha=0.7,
|
|
59
|
-
edgecolors='white')
|
|
60
|
-
colorbar = False
|
|
61
|
-
|
|
62
|
-
# dealing
|
|
63
|
-
dot = np.linspace(s_data.min(), s_data.max(), 6).round(-1)
|
|
64
|
-
|
|
65
|
-
for dott in dot[1:-1]:
|
|
66
|
-
plt.scatter([], [], c='k', alpha=0.8, s=50 * (dott / s_data.max()) ** 1.5, label='{:.0f}'.format(dott))
|
|
67
|
-
|
|
68
|
-
plt.legend(title=Unit(s))
|
|
69
|
-
|
|
70
|
-
else:
|
|
71
|
-
df_ = df.dropna(subset=[x, y]).copy()
|
|
72
|
-
x_data, y_data = df_[x].to_numpy(), df_[y].to_numpy()
|
|
73
|
-
|
|
74
|
-
scatter = ax.scatter(x_data, y_data, s=30, color='#7a97c9', alpha=0.7, edgecolors='white')
|
|
75
|
-
colorbar = False
|
|
76
|
-
|
|
77
|
-
xlim = kwargs.get('xlim', (x_data.min(), x_data.max()))
|
|
78
|
-
ylim = kwargs.get('ylim', (y_data.min(), y_data.max()))
|
|
79
|
-
xlabel = kwargs.get('xlabel', Unit(x))
|
|
80
|
-
ylabel = kwargs.get('ylabel', Unit(y))
|
|
81
|
-
title = kwargs.get('title', '')
|
|
82
|
-
ax.set(xlim=xlim, ylim=ylim, xlabel=xlabel, ylabel=ylabel, title=title)
|
|
83
|
-
|
|
84
|
-
# color_bar
|
|
85
|
-
if colorbar:
|
|
86
|
-
color_bar = plt.colorbar(scatter, extend='both')
|
|
87
|
-
color_bar.set_label(label=Unit(c), size=14)
|
|
88
|
-
|
|
89
|
-
if regression:
|
|
90
|
-
text, y_predict, slope = _linear_regression(x_data, y_data)
|
|
91
|
-
plt.plot(x_data, y_predict, linewidth=3, color=sns.xkcd_rgb["denim blue"], alpha=1, zorder=3)
|
|
92
|
-
|
|
93
|
-
plt.text(0.05, 0.95, f'{text}', fontdict={'weight': 'bold'}, color=sns.xkcd_rgb["denim blue"],
|
|
94
|
-
ha='left', va='top', transform=ax.transAxes)
|
|
95
|
-
|
|
96
|
-
if diagonal:
|
|
97
|
-
ax.axline((0, 0), slope=1., color='k', lw=2, ls='--', alpha=0.5, label='1:1')
|
|
98
|
-
plt.text(0.91, 0.97, r'$\bf 1:1\ Line$', color='k', ha='right', va='top', transform=ax.transAxes)
|
|
99
|
-
|
|
100
|
-
if box:
|
|
101
|
-
bins = np.linspace(x_data.min(), x_data.max(), 11, endpoint=True)
|
|
102
|
-
wid = (bins + (bins[1] - bins[0]) / 2)[0:-1]
|
|
103
|
-
|
|
104
|
-
df[x + '_bin'] = pd.cut(x=x_data, bins=bins, labels=wid)
|
|
105
|
-
|
|
106
|
-
group = x + '_bin'
|
|
107
|
-
column = y
|
|
108
|
-
grouped = df.groupby(group, observed=False)
|
|
109
|
-
|
|
110
|
-
names, vals = [], []
|
|
111
|
-
|
|
112
|
-
for i, (name, subdf) in enumerate(grouped):
|
|
113
|
-
names.append('{:.0f}'.format(name))
|
|
114
|
-
vals.append(subdf[column].dropna().values)
|
|
115
|
-
|
|
116
|
-
plt.boxplot(vals, labels=names, positions=wid, widths=(bins[1] - bins[0]) / 3,
|
|
117
|
-
showfliers=False, showmeans=True, meanline=True, patch_artist=True,
|
|
118
|
-
boxprops=dict(facecolor='#f2c872', alpha=.7),
|
|
119
|
-
meanprops=dict(color='#000000', ls='none'),
|
|
120
|
-
medianprops=dict(ls='-', color='#000000'))
|
|
121
|
-
|
|
122
|
-
plt.xlim(x_data.min(), x_data.max())
|
|
123
|
-
ax.set_xticks(bins, labels=bins.astype(int))
|
|
124
|
-
|
|
125
|
-
ax.xaxis.set_major_formatter(ScalarFormatter())
|
|
126
|
-
ax.yaxis.set_major_formatter(ScalarFormatter())
|
|
127
|
-
|
|
128
|
-
plt.show()
|
|
129
|
-
|
|
130
|
-
return fig, ax
|