1313
1414import abc
1515import logging
16- from typing import Any , Dict , List , Optional , Tuple , Union , List
16+ from typing import Any , Dict , List , Optional , Tuple , Union , Literal
17+ from matplotlib .axes import Axes
18+ from matplotlib .legend import Legend
19+ from matplotlib .figure import Figure
1720
1821import control
1922import numpy as np
@@ -800,10 +803,16 @@ def _get_fit_order(
800803
801804def plot_mu (
802805 d_scale_info : IterResult ,
803- ax : Optional [plt .Axes ] = None ,
806+ ax : Optional [Axes ] = None ,
807+ hide : Optional [Literal ["mu_omega" , "mu_fit_omega" ]] = None ,
808+ hz : bool = False ,
804809 plot_kw : Optional [Dict [str , Any ]] = None ,
805- hide : Optional [str ] = None ,
806- ) -> Tuple [plt .Figure , plt .Axes ]:
810+ subplot_kw : Optional [Dict [str , Any ]] = None ,
811+ xlabel : Optional [str ] = None ,
812+ ylabel : Optional [str ] = None ,
813+ grid_kw : Optional [Dict [str , Any ]] = None ,
814+ legend_kw : Optional [Dict [str , Any ]] = None ,
815+ ) -> Tuple [Figure , Axes ]:
807816 """Plot mu.
808817
809818 Parameters
@@ -820,8 +829,8 @@ def plot_mu(
820829
821830 Returns
822831 -------
823- Tuple[plt.Figure, plt.Axes]
824- Matplotlib :class:`plt.Figure` and :class:`plt.Axes` objects.
832+ Tuple[plt.figure. Figure, plt.axes .Axes]
833+ Matplotlib :class:`plt.figure. Figure` and :class:`plt.axes .Axes` objects.
825834
826835 Examples
827836 --------
@@ -854,44 +863,68 @@ def plot_mu(
854863 ... )
855864 >>> fig, ax = dkpy.plot_mu(d_scale_fit_info)
856865 """
866+
867+ # Parse plot settings
868+ if plot_kw is None :
869+ plot_kw = {}
870+ if subplot_kw is None :
871+ subplot_kw = {}
872+ if xlabel is None :
873+ xlabel = r"$f$ (Hz)" if hz else r"$\omega$ (rad/s)"
874+ if ylabel is None :
875+ ylabel = r"$\mu$"
876+ if grid_kw is None :
877+ grid_kw = {"linestyle" : "--" }
878+ if legend_kw is None :
879+ legend_kw = {"loc" : "lower left" }
880+
857881 # Create figure if not provided
858882 if ax is None :
859883 fig , ax = plt .subplots ()
860884 else :
861885 fig = ax .get_figure ()
886+
862887 # Set label
863- if plot_kw is None :
864- plot_kw = {}
865888 label = plot_kw .pop ("label" , "mu" )
866889 label_mu_omega = label + ""
867890 label_mu_fit_omega = label + "_fit"
891+
868892 # Clear line styles
869893 _ = plot_kw .pop ("ls" , None )
870894 _ = plot_kw .pop ("linestyle" , None )
895+
896+ # Frequency
897+ if hz :
898+ freq = d_scale_info .omega / (2 * np .pi ) # Frequency [Hz]
899+ else :
900+ freq = d_scale_info .omega # Angular frequency [rad/s]
901+
871902 # Plot mu
872903 if hide != "mu_omega" :
873904 ax .semilogx (
874- d_scale_info . omega ,
905+ freq ,
875906 d_scale_info .mu_omega ,
876907 label = label_mu_omega ,
877908 ls = "--" ,
878909 ** plot_kw ,
879910 )
880911 if hide != "mu_fit_omega" :
881912 ax .semilogx (
882- d_scale_info . omega ,
913+ freq ,
883914 d_scale_info .mu_fit_omega ,
884915 label = label_mu_fit_omega ,
885916 ** plot_kw ,
886917 )
918+
887919 # Set axis labels
888- ax .set_xlabel (r"$\omega$ (rad/s)" )
889- ax .set_ylabel (r"$\mu(\omega)$" )
920+ ax .set_xlabel (xlabel )
921+ ax .set_ylabel (ylabel )
890922 ax .set_ylim (
891923 (0.75 * np .min (d_scale_info .mu_omega ), 1.25 * np .max (d_scale_info .mu_omega ))
892924 )
893- ax .grid (linestyle = "--" )
894- ax .legend (loc = "lower left" )
925+ ax .grid (** grid_kw )
926+ ax .legend (** legend_kw )
927+
895928 # Return figure and axes
896929 return fig , ax
897930
0 commit comments