From e7837bb336ba35cb1eed7b6ac2801d6e27e87f5c Mon Sep 17 00:00:00 2001 From: fedetony <45215920+fedetony@users.noreply.github.com> Date: Wed, 11 Jun 2025 21:35:23 +0200 Subject: [PATCH 1/3] Updated to work with newer version of matplotlib 3.10.3, numpy 2.2.6 and python 3.10 --- setup.py | 2 +- smithplot/smithaxes.py | 37 ++++++++++++++++++++------------- smithplot/smithhelper.py | 7 ++++++- testbenches/smith_full_test.py | 26 ++++++++++++++++++----- testbenches/smith_short_test.py | 23 ++++++++++++++++---- 5 files changed, 70 insertions(+), 25 deletions(-) diff --git a/setup.py b/setup.py index 599f1f2..81c169c 100755 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ def read(fname): setup(name="pysmithplot", - version="0.2.0", + version="0.2.2", packages=["smithplot"], description="An extension for Matplotlib providing a projection class to generate high quality Smith Chart plots.", long_description=read('README.md'), diff --git a/smithplot/smithaxes.py b/smithplot/smithaxes.py index 2ed8cbb..db9c094 100644 --- a/smithplot/smithaxes.py +++ b/smithplot/smithaxes.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# last edit: 11.04.2018 +# last edit: 10.06.2025 ''' Library for plotting fully automatic a Smith Chart with various customizable parameters and well selected default values. It also provides the following @@ -35,8 +35,15 @@ of all given parameters. This does not work always, especially if the parameters are array-like types (e.g. numpy.ndarray). ''' - -from collections import Iterable +# changed by FG for python 3.10 +# matplotlib==3.10.3 +# numpy==2.2.6 + +try: + from collections import Iterable +except ImportError: + from collections.abc import Iterable + from numbers import Number from types import MethodType, FunctionType @@ -45,7 +52,7 @@ from matplotlib.axes import Axes from matplotlib.axis import XAxis from matplotlib.cbook import simple_linear_interpolation as linear_interpolation -from matplotlib.legend_handler import HandlerLine2D +from matplotlib.legend_handler import HandlerLine2DCompound from matplotlib.lines import Line2D from matplotlib.markers import MarkerStyle from matplotlib.patches import Circle, Arc @@ -449,18 +456,18 @@ def dummy(*args, **kwargs): self.yaxis.get_majorticklocs()): # workaround for fixing to small infinity symbol if abs(loc) > self._near_inf: - tick.label.set_size(tick.label.get_size() + + tick.label1.set_fontsize(tick.label1.get_fontsize() + self._get_key("symbol.infinity.correction")) - tick.label.set_verticalalignment('center') + tick.label1.set_verticalalignment('center') x = np.real(self._moebius_z(loc * 1j)) if x < -0.1: - tick.label.set_horizontalalignment('right') + tick.label1.set_horizontalalignment('right') elif x > 0.1: - tick.label.set_horizontalalignment('left') + tick.label1.set_horizontalalignment('left') else: - tick.label.set_horizontalalignment('center') + tick.label1.set_horizontalalignment('center') self.yaxis.set_major_formatter(self.ImagFormatter(self)) self.xaxis.set_major_formatter(self.RealFormatter(self)) @@ -507,7 +514,8 @@ def get_yaxis_transform(self, which='grid'): def get_yaxis_text1_transform(self, pixelPad): if hasattr(self, 'yaxis') and len(self.yaxis.majorTicks) > 0: - font_size = self.yaxis.majorTicks[0].label.get_size() + #font_size = self.yaxis.majorTicks[0].label.get_size() + font_size = self.yaxis.majorTicks[0].label1.get_fontsize() else: font_size = self._get_key("font.size") @@ -651,11 +659,11 @@ def imag_interp1d(self, y, steps): def legend(self, *args, **kwargs): this_axes = self - class SmithHandlerLine2D(HandlerLine2D): + class SmithHandlerLine2D(HandlerLine2DCompound): def create_artists(self, legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans): - legline, legline_marker = HandlerLine2D.create_artists(self, legend, orig_handle, xdescent, ydescent, + legline, legline_marker = HandlerLine2DCompound.create_artists(self, legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans) if hasattr(orig_handle, "_markerhacked"): @@ -728,7 +736,7 @@ def plot(self, *args, **kwargs): pass # if (converted) arg is an ndarray of complex type, split it - if isinstance(arg, np.ndarray) and arg.dtype in [np.complex, np.complex128]: + if isinstance(arg, np.ndarray) and arg.dtype in [complex, np.complex128]: new_args += z_to_xy(arg) else: new_args += (arg,) @@ -1060,7 +1068,8 @@ def draw_nonfancy(grid): y0, y1 = yticks[k:k + 2] x_div, y_div = d_mat[i, k] - + #print('*'*33+'\n',x0, x1, x_div, y0, y1, y_div) + (x0, x1, x_div, y0, y1, y_div)=(float(x0), float(x1), int(x_div), float(y0), float(y1), int(y_div)) for xs in np.linspace(x0, x1, x_div + 1)[1:]: x_lines.append([xs, y0, y1]) x_lines.append([xs, -y1, -y0]) diff --git a/smithplot/smithhelper.py b/smithplot/smithhelper.py index cba2199..54abaa3 100644 --- a/smithplot/smithhelper.py +++ b/smithplot/smithhelper.py @@ -1,7 +1,12 @@ # -*- coding: utf-8 -*- # last edit: 11.04.2018 -from collections import Iterable +# Changed by FG for python 3.10 +try: + from collections import Iterable +except ImportError: + from collections.abc import Iterable + import numpy as np diff --git a/testbenches/smith_full_test.py b/testbenches/smith_full_test.py index f10b4ce..c7ef54b 100755 --- a/testbenches/smith_full_test.py +++ b/testbenches/smith_full_test.py @@ -10,6 +10,21 @@ import numpy as np from matplotlib import rcParams, pyplot as pp + +def get_app_path() -> str: + """Gets Appliction path + + Returns: + str: Application path + """ + # determine if application is a script file or frozen exe + application_path = "" + if getattr(sys, "frozen", False): + application_path = os.path.dirname(sys.executable) + elif __file__: + application_path = os.path.dirname(__file__) + return application_path + sys.path.append("..") from smithplot.smithaxes import SmithAxes from smithplot import smithhelper @@ -19,10 +34,10 @@ # sample data steps = 40 -data = np.loadtxt("data/s11.csv", delimiter=",", skiprows=1)[::steps] +data = np.loadtxt(os.path.join(get_app_path(),"data/s11.csv"), delimiter=",", skiprows=1)[::steps] sp_data = data[:, 1] + data[:, 2] * 1j -data = np.loadtxt("data/s22.csv", delimiter=",", skiprows=1)[::steps] +data = np.loadtxt(os.path.join(get_app_path(),"data/s22.csv"), delimiter=",", skiprows=1)[::steps] z_data = 50 * (data[:, 1] + data[:, 2] * 1j) # default params @@ -147,10 +162,10 @@ def tb_markers(): i = 0 for hackline, startmarker, endmarker, rotate_marker in [[False, None, None, False], [True, "s", "^", False], - [True, "s", None, False], + [True, "s", 'None', False], [True, VStartMarker, XEndMarker, False], [True, "s", "^", True], - [True, None, "^", False]]: + [True, 'None', "^", False]]: i += 1 ax = pp.subplot(2, 3, i, projection="smith", plot_marker_hack=hackline, @@ -232,7 +247,7 @@ def tb_misc(): build_all = True -build_path = "./build" +build_path = os.path.join(get_app_path(),"build") if __name__ == '__main__': # clear and create path @@ -263,3 +278,4 @@ def tb_misc(): pp.show() print("build finished") + input("Press Enter to exit") diff --git a/testbenches/smith_short_test.py b/testbenches/smith_short_test.py index 3e43953..a2633d2 100755 --- a/testbenches/smith_short_test.py +++ b/testbenches/smith_short_test.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import sys +import os import numpy as np from matplotlib import rcParams, pyplot as pp @@ -9,12 +10,25 @@ sys.path.append("..") from smithplot import SmithAxes +def get_app_path() -> str: + """Gets Appliction path + + Returns: + str: Application path + """ + # determine if application is a script file or frozen exe + application_path = "" + if getattr(sys, "frozen", False): + application_path = os.path.dirname(sys.executable) + elif __file__: + application_path = os.path.dirname(__file__) + return application_path # sample data -data = np.loadtxt("data/s11.csv", delimiter=",", skiprows=1)[::100] +data = np.loadtxt(os.path.join(get_app_path(),"data/s11.csv"), delimiter=",", skiprows=1)[::100] val1 = data[:, 1] + data[:, 2] * 1j -data = np.loadtxt("data/s22.csv", delimiter=",", skiprows=1)[::100] +data = np.loadtxt(os.path.join(get_app_path(),"data/s22.csv"), delimiter=",", skiprows=1)[::100] val2 = data[:, 1] + data[:, 2] * 1j # plot data @@ -30,8 +44,9 @@ pp.plot(val1, markevery=1, label="equipoints=22", equipoints=22, datatype=SmithAxes.S_PARAMETER) pp.plot(val2, markevery=3, label="equipoints=22, \nmarkevery=3", equipoints=22, datatype=SmithAxes.S_PARAMETER) -leg = pp.legend(loc="lower right", fontsize=12) +#leg = +pp.legend(loc="lower right", fontsize=12) pp.title("Matplotlib Smith Chart Projection") -pp.savefig("export.pdf", format="pdf", bbox_inches="tight") +pp.savefig(os.path.join(get_app_path(),"build","export.pdf"), format="pdf", bbox_inches="tight") pp.show() From 346fefe8e483d41d5c37ea977e36505cf8287fbf Mon Sep 17 00:00:00 2001 From: fedetony <45215920+fedetony@users.noreply.github.com> Date: Wed, 11 Jun 2025 23:05:11 +0200 Subject: [PATCH 2/3] Added installing comment --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index fd86dbd..f3d9590 100755 --- a/README.md +++ b/README.md @@ -71,3 +71,8 @@ For more details and documentation, take a look into `smithplot/smithaxes.py`. ![Miscellaneous](https://github.com/vMeijin/pySmithPlot/wiki/images/examples/sample_miscellaneous.png) [Miscellaneous - PDF](https://github.com/vMeijin/pySmithPlot/wiki/images/examples/sample_miscellaneous.pdf) + +## Library Installation + +Open as administrator a command prompt in the `pySmithplot` folder +Run `python .\setup.py install_lib` From bc8ac14093f26f2e78b4d9cd2003b2517f6aea45 Mon Sep 17 00:00:00 2001 From: fedetony <45215920+fedetony@users.noreply.github.com> Date: Sat, 13 Dec 2025 11:50:38 +0100 Subject: [PATCH 3/3] Windows to linux eof issue https://stackoverflow.com/questions/5787937/git-status-shows-files-as-changed-even-though-contents-are-the-same/35204436#35204436 --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..2125666 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto \ No newline at end of file