@@ -763,7 +763,7 @@ def taylor(
763
763
764
764
def residual_hist (
765
765
self , bins = 100 , title = None , color = None , figsize = None , ax = None , ** kwargs
766
- ) -> matplotlib .axes .Axes :
766
+ ) -> matplotlib .axes .Axes | list [ matplotlib . axes . Axes ] :
767
767
"""plot histogram of residual values
768
768
769
769
Parameters
@@ -776,20 +776,67 @@ def residual_hist(
776
776
residual color, by default "#8B8D8E"
777
777
figsize : tuple, optional
778
778
figure size, by default None
779
- ax : matplotlib.axes.Axes, optional
779
+ ax : matplotlib.axes.Axes | list[matplotlib.axes.Axes] , optional
780
780
axes to plot on, by default None
781
781
**kwargs
782
782
other keyword arguments to plt.hist()
783
783
784
784
Returns
785
785
-------
786
- matplotlib.axes.Axes
786
+ matplotlib.axes.Axes | list[matplotlib.axes.Axes]
787
787
"""
788
+ cmp = self .comparer
789
+
790
+ if cmp .n_models == 1 :
791
+ return self ._residual_hist_one_model (
792
+ bins = bins ,
793
+ title = title ,
794
+ color = color ,
795
+ figsize = figsize ,
796
+ ax = ax ,
797
+ mod_name = cmp .mod_names [0 ],
798
+ ** kwargs ,
799
+ )
800
+
801
+ if ax is not None and len (ax ) != len (cmp .mod_names ):
802
+ raise ValueError ("Number of axes must match number of models" )
803
+
804
+ axs = ax if ax is not None else [None ] * len (cmp .mod_names )
805
+
806
+ for i , mod_name in enumerate (cmp .mod_names ):
807
+ cmp_model = cmp .sel (model = mod_name )
808
+ ax_mod = cmp_model .plot .residual_hist (
809
+ bins = bins ,
810
+ title = title ,
811
+ color = color ,
812
+ figsize = figsize ,
813
+ ax = axs [i ],
814
+ ** kwargs ,
815
+ )
816
+ axs [i ] = ax_mod
817
+
818
+ return axs
819
+
820
+ def _residual_hist_one_model (
821
+ self ,
822
+ bins = 100 ,
823
+ title = None ,
824
+ color = None ,
825
+ figsize = None ,
826
+ ax = None ,
827
+ mod_name = None ,
828
+ ** kwargs ,
829
+ ) -> matplotlib .axes .Axes :
830
+ """Residual histogram for one model only"""
788
831
_ , ax = _get_fig_ax (ax , figsize )
789
832
790
833
default_color = "#8B8D8E"
791
834
color = default_color if color is None else color
792
- title = f"Residuals, { self .comparer .name } " if title is None else title
835
+ title = (
836
+ f"Residuals, Observation: { self .comparer .name } , Model: { mod_name } "
837
+ if title is None
838
+ else title
839
+ )
793
840
ax .hist (self .comparer ._residual , bins = bins , color = color , ** kwargs )
794
841
ax .set_title (title )
795
842
ax .set_xlabel (f"Residuals of { self .comparer ._unit_text } " )
0 commit comments