Skip to content

TypeError: LogScale.__init__() got an unexpected keyword argument 'basex' #408

Description

@venkataratnamb20

I used the bode plot example from the documentation Ref: https://pyspice.fabrice-salvaire.fr/releases/v1.3/examples/filter/low-pass-rc-filter.html

It seems I can see two errors from long time

  1. bode_digram error
  2. Subcircuit error. (Please copy paste the code from documentation: https://pyspice.fabrice-salvaire.fr/releases/v1.3/examples/basic-usages/subcircuit.html
import math
import numpy as np
import matplotlib.pyplot as plt


import PySpice.Logging.Logging as Logging
logger = Logging.setup_logging()


from PySpice.Plot.BodeDiagram import bode_diagram
from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *


circuit = Circuit('Low-Pass RC Filter')

circuit.SinusoidalVoltageSource('input', 'in', circuit.gnd, amplitude=1@u_V)
R1 = circuit.R(1, 'in', 'out', 1@u_kΩ)
C1 = circuit.C(1, 'out', circuit.gnd, 1@u_uF)

# The break frequency is given by fc=12πRC

break_frequency = 1 / (2 * math.pi * float(R1.resistance * C1.capacitance))
print("Break frequency = {:.1f} Hz".format(break_frequency))

simulator = circuit.simulator(temperature=25, nominal_temperature=25)
analysis = simulator.ac(start_frequency=1@u_Hz, stop_frequency=1@u_MHz, number_of_points=10,  variation='dec')
# print(analysis.out)
# We plot the Bode diagram.

figure = plt.figure(1, (20, 10))
plt.title("Bode Diagram of a Low-Pass RC Filter")
axes = (plt.subplot(211), plt.subplot(212))
bode_diagram(axes=axes,
             frequency=analysis.frequency,
             gain=20*np.log10(np.absolute(analysis.out)),
             phase=np.angle(analysis.out, deg=False),
             marker='.',
             color='blue',
             linestyle='-',
         )
for axe in axes:
    axe.axvline(x=break_frequency, color='red')

plt.tight_layout()
plt.show()

IT gives the following error

2026-09-21 12:51:43,392 - PySpice.Spice.NgSpice.Shared.NgSpiceShared._init_ngspice - WARNING - Unsupported Ngspice version 39
2026-09-21 12:51:43,410 - PySpice.Probe.WaveForm.WaveForm.__array_ufunc__ - WARNING - Should be unit less
2026-09-21 12:51:43,411 - PySpice.Probe.WaveForm.WaveForm.__array_ufunc__ - WARNING - Should be unit less
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File /usr/local/lib/python3.12/site-packages/matplotlib/scale.py:178, in _make_axis_parameter_optional.<locals>.wrapper(self, *args, **kwargs)
    176 try:
    177     # Try old signature.
--> 178     sig.bind(self, *args, **kwargs)
    179 except TypeError:
    180     # Use the new signature and pass in an unused axis=None.

File /usr/local/lib/python3.12/inspect.py:3259, in Signature.bind(self, *args, **kwargs)
   3255 """Get a BoundArguments object, that maps the passed `args`
   3256 and `kwargs` to the function's signature.  Raises `TypeError`
   3257 if the passed arguments can not be bound.
   3258 """
-> 3259 return self._bind(args, kwargs)

File /usr/local/lib/python3.12/inspect.py:3248, in Signature._bind(self, args, kwargs, partial)
   3247     else:
-> 3248         raise TypeError(
   3249             'got an unexpected keyword argument {arg!r}'.format(
   3250                 arg=next(iter(kwargs))))
   3252 return self._bound_arguments_cls(self, arguments)

TypeError: got an unexpected keyword argument 'basex'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
Cell In[15], line 9
      5 
      6 figure = plt.figure(1, (20, 10))
      7 plt.title("Bode Diagram of a Low-Pass RC Filter")
      8 axes = (plt.subplot(211), plt.subplot(212))
----> 9 bode_diagram(axes=axes,
     10              frequency=analysis.frequency,
     11              gain=20*np.log10(np.absolute(analysis.out)),
     12              phase=np.angle(analysis.out, deg=False),

File /usr/local/lib/python3.12/site-packages/PySpice/Plot/BodeDiagram.py:59, in bode_diagram(axes, frequency, gain, phase, **kwargs)
     58 def bode_diagram(axes, frequency, gain, phase, **kwargs):
---> 59     bode_diagram_gain(axes[0], frequency, gain, **kwargs)
     60     bode_diagram_phase(axes[1], frequency, phase, **kwargs)

File /usr/local/lib/python3.12/site-packages/PySpice/Plot/BodeDiagram.py:36, in bode_diagram_gain(axe, frequency, gain, **kwargs)
     34 def bode_diagram_gain(axe, frequency, gain, **kwargs):
---> 36     axe.semilogx(frequency, gain, basex=10, **kwargs)
     37     axe.grid(True)
     38     axe.grid(True, which='minor')

File /usr/local/lib/python3.12/site-packages/matplotlib/axes/_axes.py:1898, in Axes.semilogx(self, *args, **kwargs)
   1858 """
   1859 Make a plot with log scaling on the x-axis.
   1860 
   (...)   1893     Objects representing the plotted data.
   1894 """
   1895 d = {k: v for k, v in kwargs.items()
   1896      if k in ['base', 'subs', 'nonpositive',
   1897               'basex', 'subsx', 'nonposx']}
-> 1898 self.set_xscale('log', **d)
   1899 return self.plot(
   1900     *args, **{k: v for k, v in kwargs.items() if k not in d})

File /usr/local/lib/python3.12/site-packages/matplotlib/axes/_base.py:75, in _axis_method_wrapper.__set_name__.<locals>.wrapper(self, *args, **kwargs)
     74 def wrapper(self, *args, **kwargs):
---> 75     return get_method(self)(*args, **kwargs)

File /usr/local/lib/python3.12/site-packages/matplotlib/axis.py:822, in Axis._set_axes_scale(self, value, **kwargs)
    819 old_default_lims = (self.get_major_locator()
    820                     .nonsingular(-np.inf, np.inf))
    821 for ax in self._get_shared_axes():
--> 822     ax._axis_map[name]._set_scale(value, **kwargs)
    823     ax._update_transScale()
    824     ax.stale = True

File /usr/local/lib/python3.12/site-packages/matplotlib/axis.py:791, in Axis._set_scale(self, value, **kwargs)
    789 def _set_scale(self, value, **kwargs):
    790     if not isinstance(value, mscale.ScaleBase):
--> 791         self._scale = mscale.scale_factory(value, self, **kwargs)
    792     else:
    793         self._scale = value

File /usr/local/lib/python3.12/site-packages/matplotlib/scale.py:946, in scale_factory(scale, axis, **kwargs)
    943 scale_cls = _api.getitem_checked(_scale_mapping, scale=scale)
    945 if _scale_has_axis_parameter[scale]:
--> 946     return scale_cls(axis, **kwargs)
    947 else:
    948     return scale_cls(**kwargs)

File /usr/local/lib/python3.12/site-packages/matplotlib/scale.py:181, in _make_axis_parameter_optional.<locals>.wrapper(self, *args, **kwargs)
    178     sig.bind(self, *args, **kwargs)
    179 except TypeError:
    180     # Use the new signature and pass in an unused axis=None.
--> 181     init_func(self, None, *args, **kwargs)
    182 else:
    183     # Use the old signature.
    184     init_func(self, *args, **kwargs)

TypeError: LogScale.__init__() got an unexpected keyword argument 'basex'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions