Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying DDataPlotter to allow testing on it #109

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions SciDataTool/GUI/DDataPlotter/DDataPlotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from matplotlib.patches import Rectangle
from matplotlib.collections import PathCollection, QuadMesh
from matplotlib.text import Annotation
from numpy import array
from numpy import array, allclose
from SciDataTool.Functions.is_axes_in_order import is_axes_in_order
from SciDataTool.Functions.Plot import TEXT_BOX

Expand Down Expand Up @@ -260,8 +260,11 @@ def format_coord(x, y, z=None, sep=", ", ind=None):
if is_annot:
# Use ticklabels
try:
x_float = float(self.ax.get_xticklabels()[-1]._text)
X_str = format(x, ".4g")
if self.ax.get_xticklabels()[-1]._text == "":
X_str = format(x, ".4g")
else:
x_float = float(self.ax.get_xticklabels()[-1]._text)
X_str = format(x, ".4g")
except:
for ticklabel in self.ax.get_xticklabels():
if ticklabel._x == x:
Expand All @@ -272,8 +275,11 @@ def format_coord(x, y, z=None, sep=", ", ind=None):
Y_str = format(y, ".4g")
else:
try:
y_float = float(self.ax.get_yticklabels()[-1]._text)
Y_str = format(y, ".4g")
if self.ax.get_yticklabels()[-1]._text == "":
Y_str = format(y, ".4g")
else:
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():
Expand Down Expand Up @@ -394,6 +400,13 @@ def set_cursor(event):
X = xdata[ind][0] # X position of the click
Y = ydata[ind][0] # Y position of the click
if self.ax.get_legend_handles_labels()[1] != []:
try:
self.ax.lines.index(plot_obj) # Test validation mode
except ValueError:
for line in self.ax.lines:
if allclose(ydata, line.get_ydata()):
plot_obj = line
break
legend = self.ax.get_legend_handles_labels()[1][
self.ax.lines.index(plot_obj)
].lstrip(" ")
Expand Down