Skip to content

Commit

Permalink
[BC] various bugs in plot GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
helene-t committed Jan 12, 2022
1 parent 35d71bf commit 74c87fb
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 54 deletions.
3 changes: 3 additions & 0 deletions SciDataTool/Functions/Plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"order": "",
"cr_band": "Bark",
"speed": "rpm",
"Rotation speed": "rpm",
"modes": "",
}

Expand All @@ -22,6 +23,7 @@
"angle": ["tooth_id", "distance"],
"freqs": ["elec_order", "mech_order"],
"wavenumber": ["space_order"],
"z": ["x L"],
}

norm_name_dict = {
Expand All @@ -31,6 +33,7 @@
"distance": "Distance",
"angle_rotor": "Rotor mechanical angle",
"tooth_id": "Stator tooth number",
"x L": "x L",
}

norm_dict = {
Expand Down
104 changes: 54 additions & 50 deletions SciDataTool/GUI/DDataPlotter/DDataPlotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,23 @@ def format_coord(x, y, z=None, sep=", "):
try:
x_float = float(self.ax.get_xticklabels()[-1]._text)
X_str = format(x, ".4g")
Y_str = format(y, ".4g")
except:
X_str = None
Y_str = None
for ticklabel in self.ax.get_xticklabels():
if ticklabel._x == x:
X_str = ticklabel._text
break
try:
y_float = float(self.ax.get_yticklabels()[-1]._text)
Y_str = format(y, ".4g")
except:
Y_str = None
for ticklabel in self.ax.get_yticklabels():
if ticklabel._y == y:
Y_str = ticklabel._text
break
if X_str is None or Y_str is None:
return ""
if X_str is None or Y_str is None:
return ""

# Recovering the input of the user
[
Expand Down Expand Up @@ -243,10 +246,10 @@ def format_coord(x, y, z=None, sep=", "):
yunit = "[" + latex(axes_selected_parsed[1].unit) + "]"

else:
ylabel = self.data.symbol

if self.data._name.lower() in SYMBOL_DICT:
ylabel = latex(SYMBOL_DICT[self.data._name.lower()])
if self.data.name.lower() in SYMBOL_DICT:
ylabel = latex(SYMBOL_DICT[self.data.name.lower()])
else:
ylabel = latex(self.data.symbol)

yunit = "[" + latex(self.data.unit) + "]"

Expand Down Expand Up @@ -339,48 +342,49 @@ def set_cursor(event):
dx = (x_max - x_min) / 50
if X is not None and Y is not None:
label = format_coord(X, Y, Z, sep="\n")
if self.text is None:
# Create label in box and black cross
self.text = self.ax.text(
X + dx,
Y,
label,
ha="left",
va="center",
bbox=text_box,
)
# Draw line
self.line = self.ax.plot(
[X, X + dx],
[Y, Y],
color="k",
linestyle="-",
linewidth=0.5,
)
# Draw circle
self.circle = self.ax.plot(
X,
Y,
".",
markerfacecolor="w",
markeredgecolor="k",
markeredgewidth=0.5,
markersize=12,
)
else:
# Update label, line and circle
self.text._x = X + dx
self.text._y = Y
self.text._text = label
self.circle[0].set_xdata(array(X))
self.circle[0].set_ydata(array(Y))
self.line[0].set_xdata(array([X, X + dx]))
self.line[0].set_ydata(array([Y, Y]))

self.ax.texts[-1].set_visible(True)
self.ax.lines[-1].set_visible(True)
self.ax.lines[-2].set_visible(True)
self.canvas.draw()
if label != "":
if self.text is None:
# Create label in box and black cross
self.text = self.ax.text(
X + dx,
Y,
label,
ha="left",
va="center",
bbox=text_box,
)
# Draw line
self.line = self.ax.plot(
[X, X + dx],
[Y, Y],
color="k",
linestyle="-",
linewidth=0.5,
)
# Draw circle
self.circle = self.ax.plot(
X,
Y,
".",
markerfacecolor="w",
markeredgecolor="k",
markeredgewidth=0.5,
markersize=12,
)
else:
# Update label, line and circle
self.text._x = X + dx
self.text._y = Y
self.text._text = label
self.circle[0].set_xdata(array(X))
self.circle[0].set_ydata(array(Y))
self.line[0].set_xdata(array([X, X + dx]))
self.line[0].set_ydata(array([Y, Y]))

self.ax.texts[-1].set_visible(True)
self.ax.lines[-1].set_visible(True)
self.ax.lines[-2].set_visible(True)
self.canvas.draw()

def delete_cursor(event):
if event.button.name == "RIGHT":
Expand Down
2 changes: 1 addition & 1 deletion SciDataTool/Methods/DataND/get_magnitude_along.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_magnitude_along(
args = args[0] # if called from another script with *args

# For dB/dBA conversions, first extraction with freqs axis
if "dB" in unit and is_sum:
if "dB" in unit and unit != self.unit and is_sum:
new_args = list(args).copy()
freq_name = None
index_freq = None
Expand Down
2 changes: 1 addition & 1 deletion SciDataTool/Methods/DataND/plot_2D_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def plot_2D_Data(
xticks = [i * round(np_max(axis.values) / 6) for i in range(7)]
else:
xticks = None
if axis.is_components and axes_list[0].extension != "list":
if axes_list[0].is_components and axes_list[0].extension != "list":
xticklabels = result[list(result)[0]]
xticks = Xdatas[0]
else:
Expand Down
16 changes: 14 additions & 2 deletions SciDataTool/Methods/DataND/plot_3D_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,23 @@ def plot_3D_Data(
x_max = min(x_max, np_max(Xdata))
if len(yticks) > 1:
if y_min is None:
y_min = max(yticks[0], -100)
if (
axes_list[1].name == "wavenumber"
or axes_list[1].corr_name == "wavenumber"
):
y_min = max(yticks[0], -100)
else:
y_min = 0
else:
y_min = max(y_min, yticks[0])
if y_max is None:
y_max = min(yticks[-1], 100)
if (
axes_list[1].name == "wavenumber"
or axes_list[1].corr_name == "wavenumber"
):
y_max = min(yticks[-1], 100)
else:
y_max = yticks[-1]
else:
y_max = min(y_max, yticks[-1])
else:
Expand Down
1 change: 1 addition & 0 deletions SciDataTool/Methods/DataPattern/get_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def get_values(
operation=None,
is_real=True,
corr_unit=None,
is_full=False,
):
"""Returns the vector 'axis' taking symmetries into account.
Parameters
Expand Down

0 comments on commit 74c87fb

Please sign in to comment.