Skip to content

Commit 1f1f54f

Browse files
committed
reduced repeated lines in plot_metric
1 parent fc5fdfb commit 1f1f54f

1 file changed

Lines changed: 26 additions & 31 deletions

File tree

gnss_lib_py/utils/visualizations.py

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -96,55 +96,50 @@ def plot_metric(navdata, *args, groupby=None, title=None, save=False,
9696
fig, axes = _get_new_fig()
9797

9898
if x_metric is None:
99+
x_data = None
100+
xlabel = "INDEX"
99101
if title is None:
100102
title = _get_label({y_metric:y_metric})
101-
plt.xlabel("INDEX")
102-
if groupby is not None:
103-
for group in np.unique(navdata[groupby]):
104-
subset = navdata.where(groupby,group)
105-
y_data = np.atleast_1d(subset[y_metric])
106-
axes.plot(range(len(y_data)), y_data,
107-
markeredgecolor = markeredgecolor,
108-
markeredgewidth = markeredgewidth,
109-
label=_get_label({groupby:group}), **kwargs)
110-
else:
111-
y_data = np.atleast_1d(navdata[y_metric])
112-
axes.plot(range(len(y_data)), y_data,
113-
markeredgecolor = markeredgecolor,
114-
markeredgewidth = markeredgewidth,
115-
**kwargs)
116103
else:
117104
if title is None:
118105
title = _get_label({x_metric:x_metric}) + " vs. " \
119106
+ _get_label({y_metric:y_metric})
120-
plt.xlabel(_get_label({x_metric:x_metric}))
121-
if groupby is not None:
122-
all_groups = np.unique(navdata[groupby])
123-
if groupby == "gnss_id":
124-
all_groups = _sort_gnss_ids(all_groups)
125-
for group in all_groups:
126-
subset = navdata.where(groupby,group)
107+
xlabel = _get_label({x_metric:x_metric})
108+
109+
if groupby is not None:
110+
all_groups = np.unique(navdata[groupby])
111+
if groupby == "gnss_id":
112+
all_groups = _sort_gnss_ids(all_groups)
113+
for group in all_groups:
114+
subset = navdata.where(groupby,group)
115+
y_data = np.atleast_1d(subset[y_metric])
116+
if x_metric is None:
117+
x_data = range(len(y_data))
118+
else:
127119
x_data = np.atleast_1d(subset[x_metric])
128-
y_data = np.atleast_1d(subset[y_metric])
129-
axes.plot(x_data, y_data,
130-
label=_get_label({groupby:group}),
131-
markeredgecolor = markeredgecolor,
132-
markeredgewidth = markeredgewidth,
133-
**kwargs)
134-
else:
135-
x_data = np.atleast_1d(navdata[x_metric])
136-
y_data = np.atleast_1d(navdata[y_metric])
137120
axes.plot(x_data, y_data,
121+
label=_get_label({groupby:group}),
138122
markeredgecolor = markeredgecolor,
139123
markeredgewidth = markeredgewidth,
140124
**kwargs)
125+
else:
126+
y_data = np.atleast_1d(navdata[y_metric])
127+
if x_metric is None:
128+
x_data = range(len(y_data))
129+
else:
130+
x_data = np.atleast_1d(navdata[x_metric])
131+
axes.plot(x_data, y_data,
132+
markeredgecolor = markeredgecolor,
133+
markeredgewidth = markeredgewidth,
134+
**kwargs)
141135

142136
handles, _ = axes.get_legend_handles_labels()
143137
if len(handles) > 0:
144138
plt.legend(loc="upper left", bbox_to_anchor=(1.05, 1),
145139
title=_get_label({groupby:groupby}))
146140

147141
plt.title(title)
142+
plt.xlabel(xlabel)
148143
plt.ylabel(_get_label({y_metric:y_metric}))
149144
fig.tight_layout()
150145

0 commit comments

Comments
 (0)