Skip to content

Commit

Permalink
Fixed log-scale matplotlib compatibility for v3.2
Browse files Browse the repository at this point in the history
The matplotlib package removed all axis directions from the base
parameters for logarithmic scaling functions in v3.2.0 and up.

This commit supports both the original "basex" and "basey" parameters
for older versions of matplotlib and the new "base" parameter for more
recent versions of matplotlib.

Signed-off-by: Frey Alfredsson <[email protected]>
  • Loading branch information
freysteinn committed Jul 4, 2023
1 parent 6959463 commit fab9c25
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions flent/plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
HAS_MATPLOTLIB = False
MPL_VER = LooseVersion("0")


PLOT_KWARGS = (
'alpha',
'antialiased',
Expand Down Expand Up @@ -1228,7 +1229,10 @@ def _do_scaling(self, axis, data, btm, top, unit=None, allow_log=True):
axis.set_ylim(0, top_scale)
else:
if self.log_base:
axis.set_yscale('log', basey=self.log_base)
if MPL_VER >= LooseVersion("3.2"):
axis.set_yscale('log', base=self.log_base)
else:
axis.set_yscale('log', basey=self.log_base)
axis.set_ylim(max(0, btm_scale), top_scale)
else:
axis.set_ylim(btm_scale, top_scale)
Expand Down Expand Up @@ -1874,7 +1878,10 @@ def _plot(self, results, config=None, axis=None, postfix="",
axis.set_xlim(left=min(min_value, axis.get_xlim()[0]))

if self.log_base:
axis.set_xscale('log', basex=self.log_base)
if MPL_VER >= LooseVersion("3.2"):
axis.set_xscale('log', base=self.log_base)
else:
axis.set_xscale('log', basex=self.log_base)

for a, b in zip(config['axes'], self.bounds_x):
a.set_xbound(b)
Expand Down

0 comments on commit fab9c25

Please sign in to comment.