From b19eda313a3ea8a4b0549eeb9d790de455296b0a Mon Sep 17 00:00:00 2001 From: Emily Hunt Date: Sat, 18 Jan 2025 00:27:20 +0100 Subject: [PATCH] Some matplotlib hacks --- src/sk8plotlib/matplotlib_hacks.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/sk8plotlib/matplotlib_hacks.py diff --git a/src/sk8plotlib/matplotlib_hacks.py b/src/sk8plotlib/matplotlib_hacks.py new file mode 100644 index 0000000..8dd4858 --- /dev/null +++ b/src/sk8plotlib/matplotlib_hacks.py @@ -0,0 +1,24 @@ +def fetch_matplotlib_data(fig): + ax = get_ax(fig) + lines, line_data = get_lines(ax) + return ax, lines, line_data + + +def get_ax(fig): + """Fetches the first ax associated to fig.""" + return fig.axes[0] + + +def get_lines(ax): + """Fetches all line data on an axis.""" + lines = ax.get_lines() + line_data = [] + for line in lines: + x_data = line.get_xdata() + y_data = line.get_ydata() + tuples = [] + for x, y in zip(x_data, y_data): + tuples.append((x, y)) + line_data.append(tuples) + # line_data = [[line.get_xdata(), line.get_ydata()] for i, line in enumerate(lines)] + return lines, line_data -- 2.54.0