Skip to content

Commit

Permalink
[CC] add axis name + handle log scale in plot cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
helene-t committed Jan 13, 2022
1 parent 74c87fb commit dea0929
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions SciDataTool/Functions/Plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"freqs": "frequency",
"cr_band": "critical band rate",
"z": "axial direction",
"loadcases": "load cases",
}

fft_dict = {
Expand Down
26 changes: 18 additions & 8 deletions SciDataTool/GUI/DDataPlotter/DDataPlotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,18 @@ def format_coord(x, y, z=None, sep=", "):
if ticklabel._x == x:
X_str = ticklabel._text
break
try:
y_float = float(self.ax.get_yticklabels()[-1]._text)
if "mathdefault" in 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
else:
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 ""

Expand Down Expand Up @@ -300,12 +303,17 @@ def format_coord(x, y, z=None, sep=", "):
def set_cursor(event):
plot_obj = event.artist
Z = None
legend = None
if isinstance(plot_obj, Line2D):
ind = event.ind
xdata = plot_obj.get_xdata()
ydata = plot_obj.get_ydata()
X = xdata[ind][0] # X position of the click
Y = ydata[ind][0] # Y position of the click
if self.fig.legend() not in [None, []]:
legend = (
self.fig.legend().texts[self.ax.lines.index(plot_obj)]._text
)
elif isinstance(plot_obj, PathCollection):
ind = event.ind
X = plot_obj.get_offsets().data[ind][0][0]
Expand Down Expand Up @@ -342,6 +350,8 @@ 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 legend is not None:
label = legend + "\n" + label
if label != "":
if self.text is None:
# Create label in box and black cross
Expand Down

0 comments on commit dea0929

Please sign in to comment.