The Viewer sometimes fail
Closed this issue · 3 comments
The Viewer
sometimes fails with an exception generated by the grid.
The following script works on my machine. It creates a Grid
based on a function which has a vector output.
import openturns as ot
import openturns.viewer as otv
import numpy as np
t_min = 1.e-10
t_max = 1.0
n_times = 100
timeGrid = np.linspace(t_min, t_max, n_times)
g_function = ot.SymbolicFunction(["t"], ["sin(10 * t) * t", "sin(1 / t) * t"])
timeSample = ot.Sample.BuildFromPoint(timeGrid)
result = g_function(timeSample)
grid = ot.GridLayout(1, 2)
graph = ot.Graph("", "t (s)", "T (°C)", True)
curve = ot.Curve(timeSample, result[:, 0])
graph.add(curve)
grid.setGraph(0, 0, graph)
graph = ot.Graph("", "t (s)", "c", True)
curve = ot.Curve(timeSample, result[:, 1])
graph.add(curve)
grid.setGraph(0, 1, graph)
grid.setTitle("Frasil dynamics")
view = otv.View(grid, figure_kw={"figsize": (7.0, 3.0)})
On my machine, I use Matplotlib 3.5.2 on top of Python 3.10.
But CircleCI uses Matplotlib version 3.7.0 and it fails:
ValueError: keyword grid_b is not recognized; valid keywords are ['size', 'width', 'color', etc.]
On top of the error stack, there is the Viewer:
File ~/project/AS-Frasil/viewer.py:295, in View.__init__(self, graph, pixelsize, figure, figure_kw, axes, plot_kw, axes_kw, bar_kw, pie_kw, polygon_kw, polygoncollection_kw, contour_kw, step_kw, clabel_kw, text_kw, legend_kw, add_legend, square_axes, **kwargs)
290 if (graph.getLogScale() == ot.GraphImplementation.LOGY) or (
291 graph.getLogScale() == ot.GraphImplementation.LOGXY
292 ):
293 self._ax[0].set_yscale("log")
--> 295 self._ax[0].grid(b=graph.getGrid())
297 # use scientific notation on non-log axis
298 axis_mask = {
299 ot.GraphImplementation.NONE: "both",
300 ot.GraphImplementation.LOGX: "y",
301 ot.GraphImplementation.LOGY: "x",
302 ot.GraphImplementation.LOGXY: None,
303 }
I cannot reproduce the bug. However, my guess is that the faulty line is:
openturns/python/src/viewer.py
Line 299 in 986ec5b
I cannot explain why there is a b = graph.getGrid()
input argument to Matplotlib's grid
function. In my opinion, this should be:
self._ax[0].grid(graph.getGrid())
already fixed in #2221
Ok, thank you for that. I will stick to matplotlib 3.4.3 until I can access OT v1.21.
any version <3.7 is ok