MoxTools 0.1__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 MoxTools might be problematic. Click here for more details.
- MoxTools-0.1.dist-info/METADATA +6 -0
- MoxTools-0.1.dist-info/RECORD +14 -0
- MoxTools-0.1.dist-info/WHEEL +5 -0
- MoxTools-0.1.dist-info/top_level.txt +1 -0
- MxTools/__init__.py +16 -0
- MxTools/asmt_tool.py +114 -0
- MxTools/chart.py +560 -0
- MxTools/dataIO.py +152 -0
- MxTools/dataProc.py +92 -0
- MxTools/fileMg.py +119 -0
- MxTools/lsf.py +183 -0
- MxTools/radarIO.py +395 -0
- MxTools/radarSP.py +702 -0
- MxTools/testImage.py +59 -0
MxTools/chart.py
ADDED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import matplotlib.pyplot as plt
|
|
2
|
+
|
|
3
|
+
# plot_data = {
|
|
4
|
+
# **{
|
|
5
|
+
# f"Ch{ch}_RX{ant1}-{ant2}": [phaseE_data[0,:], phaseE_data[ch,:]]
|
|
6
|
+
# for idx, (ch, ant1, ant2) in enumerate([(3, 3, 2), (4, 1, 4), (6, 12, 34)])
|
|
7
|
+
# },
|
|
8
|
+
# "title": "E-Plane Phase Difference",
|
|
9
|
+
# "xlabel": "Degree",
|
|
10
|
+
# "ylabel": "Power",
|
|
11
|
+
# "xtick": [15, -90, 90], # [interval, min, max]
|
|
12
|
+
# "ytick": [20, -180, 180], # [interval, min, max]
|
|
13
|
+
# }
|
|
14
|
+
|
|
15
|
+
# # 繪製圖表
|
|
16
|
+
# fig_num = chart.plot_plotMultiSeries(plot_data, legend_position=(0.8,1))
|
|
17
|
+
# fig_num.savefig(outPath + r"/" +"E_plane_phaseDiff", dpi=130)
|
|
18
|
+
def plot_plotMultiSeries(pD: dict, figsize: tuple = (8, 6), legend_position: tuple = (1.05, 1)):
|
|
19
|
+
"""
|
|
20
|
+
Plots multiple line series with customizable styles, transparency, and labels.
|
|
21
|
+
|
|
22
|
+
Parameters:
|
|
23
|
+
pD (dict): Plot configuration dictionary containing:
|
|
24
|
+
- Data series (e.g., "dataName1", "dataName2", ...): List of [x, y] data points.
|
|
25
|
+
- "style" (list): Line styles for each series (e.g., '-', '--', 'o').
|
|
26
|
+
- "alpha" (list): Transparency values for each series.
|
|
27
|
+
- "title" (str): Plot title.
|
|
28
|
+
- "xlabel" (str): Label for the x-axis.
|
|
29
|
+
- "ylabel" (str): Label for the y-axis.
|
|
30
|
+
- "xtick" (list): [interval, min, max] for x-axis ticks.
|
|
31
|
+
- "ytick" (list): [interval, min, max] for y-axis ticks.
|
|
32
|
+
figsize (tuple): Figure size in inches (width, height). Defaults to (8, 6).
|
|
33
|
+
legend_position (tuple): Tuple specifying the legend position using bbox_to_anchor. Defaults to (1.05, 1).
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
matplotlib.figure.Figure: The figure object of the plot.
|
|
37
|
+
|
|
38
|
+
Raises:
|
|
39
|
+
ValueError: If the length of "style" or "alpha" does not match the number of data series.
|
|
40
|
+
"""
|
|
41
|
+
# Initialize plot with figsize
|
|
42
|
+
fig_num = plt.figure(figsize=figsize)
|
|
43
|
+
|
|
44
|
+
# Extract plotting keys
|
|
45
|
+
non_plot_keys = {"style", "alpha", "title", "xlabel", "ylabel", "xtick", "ytick"}
|
|
46
|
+
plot_keys = [key for key in pD if key not in non_plot_keys]
|
|
47
|
+
|
|
48
|
+
num_series = len(plot_keys)
|
|
49
|
+
ylabel = pD.get("ylabel", "Y-axis")
|
|
50
|
+
xlabel = pD.get("xlabel", "X-axis")
|
|
51
|
+
title = pD.get("title", "Title")
|
|
52
|
+
ytick = pD.get("ytick", [0, 0, 0])
|
|
53
|
+
xtick = pD.get("xtick", [0, 0, 0])
|
|
54
|
+
style = pD.get("style", ["-"] * num_series)
|
|
55
|
+
alpha = pD.get("alpha", [1.0] * num_series)
|
|
56
|
+
|
|
57
|
+
# Ensure style and alpha lists are valid
|
|
58
|
+
if len(style) < num_series or len(alpha) < num_series:
|
|
59
|
+
raise ValueError("Length of 'style' and 'alpha' must match the number of data series.")
|
|
60
|
+
|
|
61
|
+
# Plot each data series
|
|
62
|
+
for idx, key in enumerate(plot_keys):
|
|
63
|
+
x_data, y_data = pD[key]
|
|
64
|
+
plt.plot(x_data, y_data, style[idx], alpha=alpha[idx], label=key)
|
|
65
|
+
|
|
66
|
+
# Set title and labels
|
|
67
|
+
plt.title(title)
|
|
68
|
+
plt.ylabel(ylabel)
|
|
69
|
+
plt.xlabel(xlabel)
|
|
70
|
+
|
|
71
|
+
# Configure y-axis ticks and limits
|
|
72
|
+
if ytick[0] != 0:
|
|
73
|
+
plt.yticks(range(ytick[1], ytick[2] + ytick[0], ytick[0])) # min # max + interval # interval
|
|
74
|
+
plt.ylim((ytick[1], ytick[2])) # min, max
|
|
75
|
+
|
|
76
|
+
# Configure x-axis ticks and limits
|
|
77
|
+
if xtick[0] != 0:
|
|
78
|
+
plt.xticks(range(xtick[1], xtick[2] + xtick[0], xtick[0])) # min # max + interval # interval
|
|
79
|
+
plt.xlim((xtick[1], xtick[2])) # min, max
|
|
80
|
+
|
|
81
|
+
# Add legend and layout adjustment
|
|
82
|
+
if legend_position is not None:
|
|
83
|
+
plt.legend(bbox_to_anchor=legend_position, loc="upper left", fontsize="small")
|
|
84
|
+
else:
|
|
85
|
+
plt.legend(loc="upper right", fontsize="small")
|
|
86
|
+
plt.tight_layout()
|
|
87
|
+
|
|
88
|
+
return fig_num
|
|
89
|
+
|
|
90
|
+
# plot_data = {
|
|
91
|
+
# "data1": np.random.rand(100),
|
|
92
|
+
# "data2": np.random.rand(100),
|
|
93
|
+
# "data3": np.random.rand(100),
|
|
94
|
+
# "data4": np.random.rand(100),
|
|
95
|
+
# "alpha": [0.9, 0.6,0.9, 0.6,0.9, 0.6],
|
|
96
|
+
# "style": ["-", "--","-", "--","-", "--"], # for each data
|
|
97
|
+
# "series_per_subplot": [2, 2], # 每個子圖繪製 2 條數據
|
|
98
|
+
# "title": "Dynamic Subplots with Default Size",
|
|
99
|
+
# "ylabel": ["Amplitude 1", "Amplitude 2"],
|
|
100
|
+
# "xlabel": "FFT Index",
|
|
101
|
+
# "ytick": [[10, 0, 100], [20, -50, 50]],
|
|
102
|
+
# }
|
|
103
|
+
# fig = plot_nx1_subplots(plot_data, nrows=2, figsize=(12, 6)) # 自定義圖表大小
|
|
104
|
+
# fig_num.savefig(outPath + r"/" + fn + "_spectrum_ch1_3", dpi=130)
|
|
105
|
+
def plot_nx1_subplots(dataDict: dict, nrows: int, figsize: tuple = (8, 8), legend_position: tuple = (1.05, 1)):
|
|
106
|
+
"""
|
|
107
|
+
Draws an nx1 subplot chart with a dynamic number of data series in each subplot.
|
|
108
|
+
|
|
109
|
+
Parameters:
|
|
110
|
+
dataDict (dict): A dictionary containing data and plot configurations:
|
|
111
|
+
- Keys for data series (e.g., "data1", "data2", ...).
|
|
112
|
+
- "series_per_subplot" (list): Number of data series in each subplot.
|
|
113
|
+
- "alpha" (list): Transparency values for the data series.
|
|
114
|
+
- "style" (list): Line styles for the data series.
|
|
115
|
+
- "title" (str): Title of the plot.
|
|
116
|
+
- "ylabel" (list): Y-axis labels for the subplots.
|
|
117
|
+
- "xlabel" (str): Label for the shared x-axis.
|
|
118
|
+
- "ytick" (list of lists): Y-axis ticks configuration for each subplot.
|
|
119
|
+
nrows (int): Number of rows (subplots) in the chart.
|
|
120
|
+
figsize (tuple, optional): Figure size in inches (width, height). Defaults to `(8, 8)`.
|
|
121
|
+
legend_position (tuple, optional): Tuple specifying the legend position using bbox_to_anchor. Defaults to (1.05, 1).
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
matplotlib.figure.Figure: The figure object of the plot.
|
|
125
|
+
"""
|
|
126
|
+
# Extract and validate data
|
|
127
|
+
data_keys = [
|
|
128
|
+
key for key in dataDict.keys() if key not in {"series_per_subplot", "alpha", "style", "title", "ylabel", "xlabel", "ytick"}
|
|
129
|
+
]
|
|
130
|
+
data = [dataDict[key] for key in data_keys] # Get the data series
|
|
131
|
+
ylabels = dataDict.get("ylabel", [""] * nrows)
|
|
132
|
+
ytick = dataDict.get("ytick", [[0, 0, 0]] * nrows)
|
|
133
|
+
xlabel = dataDict.get("xlabel", "X-axis")
|
|
134
|
+
title = dataDict.get("title", "Title")
|
|
135
|
+
alpha = dataDict.get("alpha", [1.0] * len(data_keys)) # Default alpha values
|
|
136
|
+
style = dataDict.get("style", ["-"] * len(data_keys)) # Default line styles
|
|
137
|
+
series_per_subplot = dataDict.get("series_per_subplot", [2] * nrows) # Default 2 series per subplot
|
|
138
|
+
|
|
139
|
+
# Create figure and subplots
|
|
140
|
+
fig, axs = plt.subplots(nrows, 1, figsize=figsize, constrained_layout=True)
|
|
141
|
+
|
|
142
|
+
# Ensure axs is iterable (in case of a single subplot)
|
|
143
|
+
if nrows == 1:
|
|
144
|
+
axs = [axs]
|
|
145
|
+
|
|
146
|
+
# Track data index
|
|
147
|
+
data_idx = 0
|
|
148
|
+
|
|
149
|
+
# Loop through subplots
|
|
150
|
+
for i, ax in enumerate(axs):
|
|
151
|
+
# Get the number of series for this subplot
|
|
152
|
+
num_series = series_per_subplot[i]
|
|
153
|
+
|
|
154
|
+
# Plot each series for the current subplot
|
|
155
|
+
for j in range(num_series):
|
|
156
|
+
if data_idx < len(data_keys): # Ensure index is valid
|
|
157
|
+
ax.plot(
|
|
158
|
+
range(len(data[data_idx])),
|
|
159
|
+
data[data_idx],
|
|
160
|
+
style[data_idx],
|
|
161
|
+
alpha=alpha[data_idx],
|
|
162
|
+
label=data_keys[data_idx],
|
|
163
|
+
)
|
|
164
|
+
data_idx += 1
|
|
165
|
+
|
|
166
|
+
# Set y-axis label
|
|
167
|
+
ax.set_ylabel(ylabels[i])
|
|
168
|
+
|
|
169
|
+
# Set y-axis ticks if specified
|
|
170
|
+
if ytick[i][0] != 0:
|
|
171
|
+
ax.set_yticks(range(ytick[i][1], ytick[i][2] + ytick[i][0], ytick[i][0]))
|
|
172
|
+
|
|
173
|
+
# Add grid and legend
|
|
174
|
+
ax.grid(linestyle=":")
|
|
175
|
+
if legend_position is not None:
|
|
176
|
+
ax.legend(bbox_to_anchor=legend_position, loc="upper left", fontsize="small")
|
|
177
|
+
else:
|
|
178
|
+
ax.legend(loc="upper right", fontsize="small")
|
|
179
|
+
|
|
180
|
+
# Set common x-axis label for the last subplot
|
|
181
|
+
axs[-1].set_xlabel(xlabel)
|
|
182
|
+
|
|
183
|
+
# Set title for the entire figure
|
|
184
|
+
fig.suptitle(title, fontsize=14)
|
|
185
|
+
|
|
186
|
+
return fig
|
|
187
|
+
|
|
188
|
+
# plot_data = {
|
|
189
|
+
# "clst0_base": [baseCSV_df["clst_x0"].iloc[idx_range].tolist(), baseCSV_df["clst_z0"].iloc[idx_range].tolist()],
|
|
190
|
+
# "clst0_target": [compareCSV_df["clst_x0"].iloc[idx_range].tolist(), compareCSV_df["clst_z0"].iloc[idx_range].tolist()],
|
|
191
|
+
# # "style": ["o", "o"],
|
|
192
|
+
# "size": [20, 10],
|
|
193
|
+
# "alpha": [0.4, 0.8],
|
|
194
|
+
# "title": f"Compare with:{fn}[{idx_range.start}:{idx_range.stop}]",
|
|
195
|
+
# "xlabel": "X(mm)",
|
|
196
|
+
# "ylabel": "Z(mm)",
|
|
197
|
+
# # "xtick": [1, 0, 6],
|
|
198
|
+
# # "ytick": [1000, 0, 15000],
|
|
199
|
+
# "ratio": "keep",
|
|
200
|
+
# "x-invert": "True",
|
|
201
|
+
# }
|
|
202
|
+
def plot_scatter(pD: dict, figsize: tuple = (8, 6), legend_position: tuple = (1.05, 1)):
|
|
203
|
+
"""
|
|
204
|
+
Plots a multi-series scatter chart with customizable styles, sizes, and transparency.
|
|
205
|
+
|
|
206
|
+
Parameters:
|
|
207
|
+
pD (dict): Plot configuration dictionary containing:
|
|
208
|
+
- Data series (e.g., "data1", "data2", ...): List of [x, y] data points.
|
|
209
|
+
- "style" (list): Marker styles for each series (e.g., 'o', '*', 'x').
|
|
210
|
+
- "size" (list): Marker sizes for each series.
|
|
211
|
+
- "alpha" (list): Transparency values for each series.
|
|
212
|
+
- "title" (str): Plot title.
|
|
213
|
+
- "xlabel" (str): Label for the x-axis.
|
|
214
|
+
- "ylabel" (str): Label for the y-axis.
|
|
215
|
+
- "xtick" (list): [interval, min, max] for x-axis ticks.
|
|
216
|
+
- "ytick" (list): [interval, min, max] for y-axis ticks.
|
|
217
|
+
- "ratio" (str): Whether to keep equal aspect ratio ("keep" or "nonkeep").
|
|
218
|
+
- "x-invert" (str): Whether to invert the x-axis ("True" or "False").
|
|
219
|
+
figsize (tuple, optional): Figure size in inches (width, height). Defaults to `(8, 6)`.
|
|
220
|
+
legend_position (tuple, optional): Tuple specifying the legend position using bbox_to_anchor. Defaults to `(1.05, 1)`.
|
|
221
|
+
|
|
222
|
+
Returns:
|
|
223
|
+
matplotlib.figure.Figure: The figure object of the plot.
|
|
224
|
+
"""
|
|
225
|
+
|
|
226
|
+
# Extract and validate data series
|
|
227
|
+
non_plot_keys = {"style", "size", "alpha", "title", "xlabel", "ylabel", "xtick", "ytick", "ratio", "x-invert"}
|
|
228
|
+
plot_keys = [key for key in pD if key not in non_plot_keys]
|
|
229
|
+
num_series = len(plot_keys)
|
|
230
|
+
|
|
231
|
+
if num_series == 0:
|
|
232
|
+
raise ValueError("No valid data series found in 'pD'.")
|
|
233
|
+
|
|
234
|
+
# Extract configurations with default values
|
|
235
|
+
styles = pD.get("style", ["o"] * num_series)
|
|
236
|
+
sizes = pD.get("size", [10] * num_series)
|
|
237
|
+
alphas = pD.get("alpha", [1.0] * num_series)
|
|
238
|
+
xlabel = pD.get("xlabel", "X-axis")
|
|
239
|
+
ylabel = pD.get("ylabel", "Y-axis")
|
|
240
|
+
title = pD.get("title", "Scatter Plot")
|
|
241
|
+
xtick = pD.get("xtick", [0, 0, 0])
|
|
242
|
+
ytick = pD.get("ytick", [0, 0, 0])
|
|
243
|
+
ratio = pD.get("ratio", "nonkeep")
|
|
244
|
+
x_invert = pD.get("x-invert", "False")
|
|
245
|
+
|
|
246
|
+
# Validate list lengths
|
|
247
|
+
if len(styles) < num_series or len(sizes) < num_series or len(alphas) < num_series:
|
|
248
|
+
raise ValueError("Length of 'style', 'size', and 'alpha' must match the number of data series.")
|
|
249
|
+
|
|
250
|
+
# Create figure with specified size
|
|
251
|
+
fig, ax = plt.subplots(figsize=figsize)
|
|
252
|
+
|
|
253
|
+
# Plot each data series
|
|
254
|
+
for idx, key in enumerate(plot_keys):
|
|
255
|
+
x_data, y_data = pD[key]
|
|
256
|
+
ax.scatter(x_data, y_data, marker=styles[idx], s=sizes[idx], alpha=alphas[idx], label=key)
|
|
257
|
+
|
|
258
|
+
# Set title and labels
|
|
259
|
+
ax.set_title(title)
|
|
260
|
+
ax.set_xlabel(xlabel)
|
|
261
|
+
ax.set_ylabel(ylabel)
|
|
262
|
+
|
|
263
|
+
# Configure x-axis ticks and limits
|
|
264
|
+
if xtick[0] != 0:
|
|
265
|
+
ax.set_xticks(range(xtick[1], xtick[2] + xtick[0], xtick[0]))
|
|
266
|
+
ax.set_xlim((xtick[1], xtick[2]))
|
|
267
|
+
|
|
268
|
+
# Configure y-axis ticks and limits
|
|
269
|
+
if ytick[0] != 0:
|
|
270
|
+
ax.set_yticks(range(ytick[1], ytick[2] + ytick[0], ytick[0]))
|
|
271
|
+
ax.set_ylim((ytick[1], ytick[2]))
|
|
272
|
+
|
|
273
|
+
# Configure grid, aspect ratio, and x-axis inversion
|
|
274
|
+
ax.grid(linestyle=":")
|
|
275
|
+
if ratio == "keep":
|
|
276
|
+
ax.set_aspect("equal")
|
|
277
|
+
if x_invert == "True":
|
|
278
|
+
ax.invert_xaxis()
|
|
279
|
+
|
|
280
|
+
# Add legend with user-defined position
|
|
281
|
+
if legend_position is not None:
|
|
282
|
+
ax.legend(bbox_to_anchor=legend_position, loc="upper left", fontsize="small")
|
|
283
|
+
else:
|
|
284
|
+
ax.legend(loc="upper right", fontsize="small")
|
|
285
|
+
|
|
286
|
+
plt.tight_layout()
|
|
287
|
+
|
|
288
|
+
return fig
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
######################
|
|
292
|
+
# style setting #
|
|
293
|
+
######################
|
|
294
|
+
def style_basic(title, xlab, ylab, xRange, yRange, keep_ratio, x_invert):
|
|
295
|
+
plt.title(title)
|
|
296
|
+
plt.xlabel(xlab)
|
|
297
|
+
plt.ylabel(ylab)
|
|
298
|
+
if xRange != 0:
|
|
299
|
+
xRange = int(xRange / 2)
|
|
300
|
+
plt.xticks(range(-xRange, xRange + 1, 1))
|
|
301
|
+
plt.xlim((-xRange, xRange)) # limit X-axis range
|
|
302
|
+
if yRange != 0:
|
|
303
|
+
plt.yticks(range(0, yRange + 1, 1))
|
|
304
|
+
plt.ylim((0, yRange)) # limit Y-axis range
|
|
305
|
+
if x_invert == True:
|
|
306
|
+
plt.gca().invert_xaxis()
|
|
307
|
+
plt.grid(linestyle=":")
|
|
308
|
+
if keep_ratio == True:
|
|
309
|
+
plt.gca().set_aspect("equal")
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
#######################
|
|
313
|
+
# plot chart #
|
|
314
|
+
#######################
|
|
315
|
+
def plot_clst_detout(title, clstData: dict, detoutData: dict, xRange, yRange):
|
|
316
|
+
fig_num = plt.figure()
|
|
317
|
+
plt.scatter(clstData["frameNo"], clstData["clst_r"], s=3, alpha=0.7, label="Clst")
|
|
318
|
+
if not (detoutData == {}):
|
|
319
|
+
plt.plot(
|
|
320
|
+
detoutData["frameNo"],
|
|
321
|
+
detoutData["detout"],
|
|
322
|
+
color="red",
|
|
323
|
+
markersize=2,
|
|
324
|
+
alpha=0.7,
|
|
325
|
+
label="DETOUT",
|
|
326
|
+
)
|
|
327
|
+
style_basic(title, "FrameNo", "Distance(m)/DETOUT", xRange, yRange, False, False)
|
|
328
|
+
plt.legend()
|
|
329
|
+
return fig_num
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def hist_subplot31_2data(dataDict: dict):
|
|
335
|
+
|
|
336
|
+
data_keys = list(dataDict.keys())
|
|
337
|
+
bins_num = 50
|
|
338
|
+
|
|
339
|
+
fig_num = plt.figure()
|
|
340
|
+
plt.subplot(311)
|
|
341
|
+
plt.hist(dataDict[data_keys[0]], bins=bins_num, alpha=1, label=data_keys[0])
|
|
342
|
+
plt.hist(dataDict[data_keys[1]], bins=bins_num, alpha=0.5, label=data_keys[1])
|
|
343
|
+
plt.title(dataDict["title"])
|
|
344
|
+
plt.ylabel(dataDict["ylabel"][0])
|
|
345
|
+
if dataDict["xtick"][1] != 0:
|
|
346
|
+
plt.xticks(
|
|
347
|
+
range(
|
|
348
|
+
dataDict["xtick"][0],
|
|
349
|
+
dataDict["xtick"][2] + dataDict["xtick"][1],
|
|
350
|
+
dataDict["xtick"][1],
|
|
351
|
+
)
|
|
352
|
+
)
|
|
353
|
+
plt.grid(linestyle=":")
|
|
354
|
+
plt.legend(bbox_to_anchor=(1, 1), loc="upper left", fontsize="small")
|
|
355
|
+
plt.tight_layout()
|
|
356
|
+
|
|
357
|
+
plt.subplot(312)
|
|
358
|
+
plt.hist(dataDict[data_keys[2]], bins=bins_num, alpha=1, label=data_keys[2])
|
|
359
|
+
plt.hist(dataDict[data_keys[3]], bins=bins_num, alpha=0.5, label=data_keys[3])
|
|
360
|
+
plt.ylabel(dataDict["ylabel"][1])
|
|
361
|
+
if dataDict["xtick"][1] != 0:
|
|
362
|
+
plt.xticks(
|
|
363
|
+
range(
|
|
364
|
+
dataDict["xtick"][0],
|
|
365
|
+
dataDict["xtick"][2] + dataDict["xtick"][1],
|
|
366
|
+
dataDict["xtick"][1],
|
|
367
|
+
)
|
|
368
|
+
)
|
|
369
|
+
plt.grid(linestyle=":")
|
|
370
|
+
plt.legend(bbox_to_anchor=(1, 1), loc="upper left", fontsize="small")
|
|
371
|
+
plt.tight_layout()
|
|
372
|
+
|
|
373
|
+
plt.subplot(313)
|
|
374
|
+
plt.hist(dataDict[data_keys[4]], bins=bins_num, alpha=1, label=data_keys[4])
|
|
375
|
+
plt.hist(dataDict[data_keys[5]], bins=bins_num, alpha=0.5, label=data_keys[5])
|
|
376
|
+
plt.ylabel(dataDict["ylabel"][2])
|
|
377
|
+
plt.xlabel(dataDict["xlabel"])
|
|
378
|
+
if dataDict["xtick"][1] != 0:
|
|
379
|
+
plt.xticks(
|
|
380
|
+
range(
|
|
381
|
+
dataDict["xtick"][0],
|
|
382
|
+
dataDict["xtick"][2] + dataDict["xtick"][1],
|
|
383
|
+
dataDict["xtick"][1],
|
|
384
|
+
)
|
|
385
|
+
)
|
|
386
|
+
plt.grid(linestyle=":")
|
|
387
|
+
plt.legend(bbox_to_anchor=(1, 1), loc="upper left", fontsize="small")
|
|
388
|
+
plt.tight_layout()
|
|
389
|
+
|
|
390
|
+
return fig_num
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
# input Dict example
|
|
394
|
+
# plot_data = {
|
|
395
|
+
# "lab1_x": dict["dataName1"],
|
|
396
|
+
# "lab1_y": dict["dataName2"],
|
|
397
|
+
# "lab2_x": dict["dataName3"],
|
|
398
|
+
# "lab2_y": dict["dataName4"],
|
|
399
|
+
# "data1_lab": "lab1",
|
|
400
|
+
# "data2_lab": "lab2",
|
|
401
|
+
# "title": "Frame No:{:d}".format(frameNo),
|
|
402
|
+
# "ylabel": "ybal",
|
|
403
|
+
# "xlabel": "Sample Point",
|
|
404
|
+
# "ytick": [0, 0, 0], # [interval, min ,max]
|
|
405
|
+
# "xtick": [0, 0, 0], # [interval, min ,max]
|
|
406
|
+
# "ratio": "nonkeep", # keep or nonkeep
|
|
407
|
+
# "x-invert": "True"
|
|
408
|
+
# }
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def plot_scatter_2data(dataDict: dict):
|
|
412
|
+
lab1_x = list(dataDict.keys())[0]
|
|
413
|
+
lab1_y = list(dataDict.keys())[1]
|
|
414
|
+
lab2_x = list(dataDict.keys())[2]
|
|
415
|
+
lab2_y = list(dataDict.keys())[3]
|
|
416
|
+
|
|
417
|
+
data1_x = dataDict[lab1_x]
|
|
418
|
+
data1_y = dataDict[lab1_y]
|
|
419
|
+
data2_x = dataDict[lab2_x]
|
|
420
|
+
data2_y = dataDict[lab2_y]
|
|
421
|
+
|
|
422
|
+
data1_lab = dataDict["data1_lab"]
|
|
423
|
+
data2_lab = dataDict["data2_lab"]
|
|
424
|
+
ylab = dataDict["ylabel"]
|
|
425
|
+
xlab = dataDict["xlabel"]
|
|
426
|
+
|
|
427
|
+
ytick_interval = dataDict["ytick"][0]
|
|
428
|
+
ytick_min = dataDict["ytick"][1]
|
|
429
|
+
ytick_max = dataDict["ytick"][2]
|
|
430
|
+
|
|
431
|
+
xtick_interval = dataDict["xtick"][0]
|
|
432
|
+
xtick_min = dataDict["xtick"][1]
|
|
433
|
+
xtick_max = dataDict["xtick"][2]
|
|
434
|
+
|
|
435
|
+
fig_num = plt.figure()
|
|
436
|
+
|
|
437
|
+
plt.scatter(data1_x, data1_y, marker="*", s=20.5, alpha=0.8, label=data1_lab)
|
|
438
|
+
plt.scatter(data2_x, data2_y, s=4.5, alpha=0.8, label=data2_lab)
|
|
439
|
+
|
|
440
|
+
plt.title(dataDict["title"])
|
|
441
|
+
plt.ylabel(ylab)
|
|
442
|
+
plt.xlabel(xlab)
|
|
443
|
+
if xtick_interval != 0:
|
|
444
|
+
plt.xticks(range(xtick_min, xtick_max + xtick_interval, xtick_interval))
|
|
445
|
+
plt.xlim((xtick_min, xtick_max))
|
|
446
|
+
if ytick_interval != 0:
|
|
447
|
+
plt.yticks(range(ytick_min, ytick_max + ytick_interval, ytick_interval))
|
|
448
|
+
plt.ylim((ytick_min, ytick_max))
|
|
449
|
+
|
|
450
|
+
plt.grid(linestyle=":")
|
|
451
|
+
plt.grid(linestyle=":")
|
|
452
|
+
if dataDict["ratio"] == "keep":
|
|
453
|
+
plt.gca().set_aspect("equal")
|
|
454
|
+
if dataDict["x-invert"] == "True":
|
|
455
|
+
plt.gca().invert_xaxis()
|
|
456
|
+
plt.legend(bbox_to_anchor=(1.05, 1), loc="upper left", fontsize="medium")
|
|
457
|
+
plt.tight_layout()
|
|
458
|
+
|
|
459
|
+
return fig_num
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
# plot_data = {
|
|
463
|
+
# "dataName1": [ [1,2,3] , [4,5,6] ], # x:[1,2,3] y:[4,5,6]
|
|
464
|
+
# "dataName2": [ [4,5,6] , [7,8,9] ],
|
|
465
|
+
# "dataName3": [ [7,8,9] , [1,2,3] ],
|
|
466
|
+
# "style" : ['o', '*', 'x', '+', '-', '-'], # color+mark+line
|
|
467
|
+
# "size" : [30, 30, 30, 30, 30, 30],
|
|
468
|
+
# "alpha" : [1, 0.8, 0.6, 0.4, 1, 1], #
|
|
469
|
+
# "title": "{:s} raw angle".format(fn),
|
|
470
|
+
# "xlabel": "counter(frame)",
|
|
471
|
+
# "ylabel": "Power/Degree",
|
|
472
|
+
# "xtick": [0, 0, 0], # [interval, min ,max]
|
|
473
|
+
# "ytick": [0, 0, 0], # [interval, min ,max]
|
|
474
|
+
# "ratio": "nonkeep", # keep or nonkeep
|
|
475
|
+
# "x-invert": "False"
|
|
476
|
+
# }
|
|
477
|
+
# fig_num = chart.plot_scatterMuti(plot_data)
|
|
478
|
+
# fig_num.savefig(outPath + r"/" + fn + "_PowerPhaseDiff", dpi=180)
|
|
479
|
+
def plot_scatterMuti(pD: dict):
|
|
480
|
+
idx = 0
|
|
481
|
+
fig_num = plt.figure()
|
|
482
|
+
for key in pD:
|
|
483
|
+
if key not in ["style", "size", "alpha", "title", "xlabel", "ylabel", "xtick", "ytick", "ratio", "x-invert"]:
|
|
484
|
+
plt.scatter(pD[key][0], pD[key][1], marker=pD["style"][idx], s=pD["size"][idx], alpha=pD["alpha"][idx], label=key)
|
|
485
|
+
idx += 1
|
|
486
|
+
|
|
487
|
+
plt.title(pD["title"])
|
|
488
|
+
plt.ylabel(pD["ylabel"])
|
|
489
|
+
plt.xlabel(pD["xlabel"])
|
|
490
|
+
|
|
491
|
+
if pD["xtick"][0] != 0: # inteval
|
|
492
|
+
plt.xticks(range(pD["xtick"][1], pD["xtick"][2] + pD["xtick"][0], pD["xtick"][0])) # (min, max+inv, inv)
|
|
493
|
+
plt.xlim((pD["xtick"][1], pD["xtick"][2]))
|
|
494
|
+
|
|
495
|
+
plt.grid(linestyle=":")
|
|
496
|
+
plt.grid(linestyle=":")
|
|
497
|
+
if pD["ratio"] == "keep":
|
|
498
|
+
plt.gca().set_aspect("equal")
|
|
499
|
+
if pD["x-invert"] == "True":
|
|
500
|
+
plt.gca().invert_xaxis()
|
|
501
|
+
plt.legend(bbox_to_anchor=(1.05, 1), loc="upper left", fontsize="medium")
|
|
502
|
+
plt.tight_layout()
|
|
503
|
+
|
|
504
|
+
return fig_num
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
# plot_data = {
|
|
508
|
+
# "a0": procData["a0"],
|
|
509
|
+
# "a1": procData["a1"],
|
|
510
|
+
# "a2": procData["a2"],
|
|
511
|
+
# "a3": procData["a3"],
|
|
512
|
+
# "a_sm1" :procData["a_sm1"],
|
|
513
|
+
# "style" : ['o', '*', 'x', '+', '-', '-', '-', '-'], # color+mark+line
|
|
514
|
+
# "alpha" : [1, 0.8, 0.6, 0.4, 1, 1, 1, 1], #
|
|
515
|
+
# "title": "{:s} raw angle".format(fn),
|
|
516
|
+
# "ylabel": "degre",
|
|
517
|
+
# "xlabel": "counter(frame)",
|
|
518
|
+
# "ytick": [0, 0, 0], # [interval, min ,max]
|
|
519
|
+
# }
|
|
520
|
+
# fig_num = chart.plot_plotMuti(plot_data)
|
|
521
|
+
# fig_num.savefig(outPath + r"/" + fn + "_raw_angle_asm1", dpi=180)
|
|
522
|
+
def plot_plotMutiA(dataDict: dict):
|
|
523
|
+
dataKeys = list(dataDict.keys())
|
|
524
|
+
|
|
525
|
+
sData = []
|
|
526
|
+
sDataLab = []
|
|
527
|
+
for key in dataKeys:
|
|
528
|
+
if key not in ["title", "xlabel", "ylabel", "ytick", "style", "alpha"]:
|
|
529
|
+
sDataLab.append(key)
|
|
530
|
+
sData.append(dataDict[key])
|
|
531
|
+
|
|
532
|
+
fig_num = plt.figure()
|
|
533
|
+
|
|
534
|
+
for i in range(len(sDataLab)):
|
|
535
|
+
plt.plot(
|
|
536
|
+
range(len(sData[i])),
|
|
537
|
+
sData[i],
|
|
538
|
+
dataDict["style"][i],
|
|
539
|
+
alpha=dataDict["alpha"][i],
|
|
540
|
+
label=sDataLab[i],
|
|
541
|
+
)
|
|
542
|
+
|
|
543
|
+
plt.title(dataDict["title"])
|
|
544
|
+
plt.ylabel(dataDict["ylabel"])
|
|
545
|
+
plt.xlabel(dataDict["xlabel"])
|
|
546
|
+
plt.legend(bbox_to_anchor=(0.75, 1.17), loc="upper left", fontsize="small")
|
|
547
|
+
if dataDict["ytick"][0] != 0:
|
|
548
|
+
plt.yticks(
|
|
549
|
+
range(
|
|
550
|
+
dataDict["ytick"][1], # min
|
|
551
|
+
dataDict["ytick"][2] + dataDict["ytick"][0], # max+interval
|
|
552
|
+
dataDict["ytick"][0], # interval
|
|
553
|
+
)
|
|
554
|
+
)
|
|
555
|
+
plt.ylim((dataDict["ytick"][1], dataDict["ytick"][2])) # min, max
|
|
556
|
+
# plt.xlim(right=len(sData[0]))
|
|
557
|
+
margin = len(sData[0]) * 0.03
|
|
558
|
+
plt.xlim(0 - margin, len(sData[0]) + margin)
|
|
559
|
+
|
|
560
|
+
return fig_num
|