Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
37 changes: 23 additions & 14 deletions smithplot/smithaxes.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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,)
Expand Down Expand Up @@ -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])
Expand Down
7 changes: 6 additions & 1 deletion smithplot/smithhelper.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
26 changes: 21 additions & 5 deletions testbenches/smith_full_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -263,3 +278,4 @@ def tb_misc():
pp.show()

print("build finished")
input("Press Enter to exit")
23 changes: 19 additions & 4 deletions testbenches/smith_short_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import sys
import os

import numpy as np
from matplotlib import rcParams, pyplot as pp
Expand All @@ -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
Expand All @@ -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()