zlatko-minev/pyEPR

`eprh.hfss_report_full_convergence` sometimes fails due to negative values in log-scale

Opened this issue · 0 comments

Calling eprh.hfss_report_full_convergence sometimes results in ValueError: Data has no positive values, and therefore can not be log-scaled.

In this case, the simulations did not converge into tight criterion, but behaved normally

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [14], in <cell line: 1>()
----> 1 eprh.hfss_report_full_convergence()

File c:\users\iqm\pyepr\pyEPR\core_distributed_analysis.py:1637, in DistributedAnalysis.hfss_report_full_convergence(self, fig, _display)
   1633 plot_convergence_solved_elem(ax0t, convergence_t.iloc[:, 0])
   1634 plot_convergence_maxdf_vs_sol(axs[2], convergence_t.iloc[:, 1],
   1635                               convergence_t.iloc[:, 0])
-> 1637 fig.tight_layout(w_pad=0.1)  # pad=0.0, w_pad=0.1, h_pad=1.0)
   1639 if _display:
   1640     from IPython.display import display

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\figure.py:3197, in Figure.tight_layout(self, pad, h_pad, w_pad, rect)
   3195 renderer = _get_renderer(self)
   3196 with getattr(renderer, "_draw_disabled", nullcontext)():
-> 3197     kwargs = get_tight_layout_figure(
   3198         self, self.axes, subplotspec_list, renderer,
   3199         pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
   3200 if kwargs:
   3201     self.subplots_adjust(**kwargs)

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\tight_layout.py:320, in get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer, pad, h_pad, w_pad, rect)
    315         return {}
    316     span_pairs.append((
    317         slice(ss.rowspan.start * div_row, ss.rowspan.stop * div_row),
    318         slice(ss.colspan.start * div_col, ss.colspan.stop * div_col)))
--> 320 kwargs = _auto_adjust_subplotpars(fig, renderer,
    321                                   shape=(max_nrows, max_ncols),
    322                                   span_pairs=span_pairs,
    323                                   subplot_list=subplot_list,
    324                                   ax_bbox_list=ax_bbox_list,
    325                                   pad=pad, h_pad=h_pad, w_pad=w_pad)
    327 # kwargs can be none if tight_layout fails...
    328 if rect is not None and kwargs is not None:
    329     # if rect is given, the whole subplots area (including
    330     # labels) will fit into the rect instead of the
   (...)
    334     # auto_adjust_subplotpars twice, where the second run
    335     # with adjusted rect parameters.

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\tight_layout.py:82, in _auto_adjust_subplotpars(fig, renderer, shape, span_pairs, subplot_list, ax_bbox_list, pad, h_pad, w_pad, rect)
     80 if ax.get_visible():
     81     try:
---> 82         bb += [ax.get_tightbbox(renderer, for_layout_only=True)]
     83     except TypeError:
     84         bb += [ax.get_tightbbox(renderer)]

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\axes\_base.py:4628, in _AxesBase.get_tightbbox(self, renderer, call_axes_locator, bbox_extra_artists, for_layout_only)
   4626 if self.yaxis.get_visible():
   4627     try:
-> 4628         bb_yaxis = self.yaxis.get_tightbbox(
   4629             renderer, for_layout_only=for_layout_only)
   4630     except TypeError:
   4631         # in case downstream library has redefined axis:
   4632         bb_yaxis = self.yaxis.get_tightbbox(renderer)

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\axis.py:1103, in Axis.get_tightbbox(self, renderer, for_layout_only)
   1100 if not self.get_visible():
   1101     return
-> 1103 ticks_to_draw = self._update_ticks()
   1105 self._update_label_position(renderer)
   1107 # go back to just this axis's tick labels

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\axis.py:1045, in Axis._update_ticks(self)
   1040 def _update_ticks(self):
   1041     """
   1042     Update ticks (position and labels) using the current data interval of
   1043     the axes.  Return the list of ticks that will be drawn.
   1044     """
-> 1045     major_locs = self.get_majorticklocs()
   1046     major_labels = self.major.formatter.format_ticks(major_locs)
   1047     major_ticks = self.get_major_ticks(len(major_locs))

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\axis.py:1277, in Axis.get_majorticklocs(self)
   1275 def get_majorticklocs(self):
   1276     """Return this Axis' major tick locations in data coordinates."""
-> 1277     return self.major.locator()

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\ticker.py:2292, in LogLocator.__call__(self)
   2290 """Return the locations of the ticks."""
   2291 vmin, vmax = self.axis.get_view_interval()
-> 2292 return self.tick_values(vmin, vmax)

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\ticker.py:2317, in LogLocator.tick_values(self, vmin, vmax)
   2314         vmin = self.axis.get_minpos()
   2316     if vmin <= 0.0 or not np.isfinite(vmin):
-> 2317         raise ValueError(
   2318             "Data has no positive values, and therefore can not be "
   2319             "log-scaled.")
   2321 _log.debug('vmin %s vmax %s', vmin, vmax)
   2323 if vmax < vmin:

ValueError: Data has no positive values, and therefore can not be log-scaled.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib_inline\backend_inline.py:43, in show(close, block)
     39 try:
     40     for figure_manager in Gcf.get_all_fig_managers():
     41         display(
     42             figure_manager.canvas.figure,
---> 43             metadata=_fetch_figure_metadata(figure_manager.canvas.figure)
     44         )
     45 finally:
     46     show._to_draw = []

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib_inline\backend_inline.py:231, in _fetch_figure_metadata(fig)
    228 # determine if a background is needed for legibility
    229 if _is_transparent(fig.get_facecolor()):
    230     # the background is transparent
--> 231     ticksLight = _is_light([label.get_color()
    232                             for axes in fig.axes
    233                             for axis in (axes.xaxis, axes.yaxis)
    234                             for label in axis.get_ticklabels()])
    235     if ticksLight.size and (ticksLight == ticksLight[0]).all():
    236         # there are one or more tick labels, all with the same lightness
    237         return {'needs_background': 'dark' if ticksLight[0] else 'light'}

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib_inline\backend_inline.py:234, in <listcomp>(.0)
    228 # determine if a background is needed for legibility
    229 if _is_transparent(fig.get_facecolor()):
    230     # the background is transparent
    231     ticksLight = _is_light([label.get_color()
    232                             for axes in fig.axes
    233                             for axis in (axes.xaxis, axes.yaxis)
--> 234                             for label in axis.get_ticklabels()])
    235     if ticksLight.size and (ticksLight == ticksLight[0]).all():
    236         # there are one or more tick labels, all with the same lightness
    237         return {'needs_background': 'dark' if ticksLight[0] else 'light'}

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\axis.py:1249, in Axis.get_ticklabels(self, minor, which)
   1247 if minor:
   1248     return self.get_minorticklabels()
-> 1249 return self.get_majorticklabels()

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\axis.py:1201, in Axis.get_majorticklabels(self)
   1199 def get_majorticklabels(self):
   1200     """Return this Axis' major tick labels, as a list of `~.text.Text`."""
-> 1201     ticks = self.get_major_ticks()
   1202     labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
   1203     labels2 = [tick.label2 for tick in ticks if tick.label2.get_visible()]

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\axis.py:1371, in Axis.get_major_ticks(self, numticks)
   1369 r"""Return the list of major `.Tick`\s."""
   1370 if numticks is None:
-> 1371     numticks = len(self.get_majorticklocs())
   1373 while len(self.majorTicks) < numticks:
   1374     # Update the new tick label properties from the old.
   1375     tick = self._get_tick(major=True)

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\axis.py:1277, in Axis.get_majorticklocs(self)
   1275 def get_majorticklocs(self):
   1276     """Return this Axis' major tick locations in data coordinates."""
-> 1277     return self.major.locator()

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\ticker.py:2292, in LogLocator.__call__(self)
   2290 """Return the locations of the ticks."""
   2291 vmin, vmax = self.axis.get_view_interval()
-> 2292 return self.tick_values(vmin, vmax)

File ~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\ticker.py:2317, in LogLocator.tick_values(self, vmin, vmax)
   2314         vmin = self.axis.get_minpos()
   2316     if vmin <= 0.0 or not np.isfinite(vmin):
-> 2317         raise ValueError(
   2318             "Data has no positive values, and therefore can not be "
   2319             "log-scaled.")
   2321 _log.debug('vmin %s vmax %s', vmin, vmax)
   2323 if vmax < vmin:

ValueError: Data has no positive values, and therefore can not be log-scaled.