Plotting error, grid_b

Hey Everybody,
Thanks for the awesome software.
I seem to be running into a bug with incompatible versions of the software.
I am running openturns version 1.20.post3 and matplotlib 3.7.1.
When I am trying to plot something with viewer, there seems to be a bug.

Here is a small mwe

import openturns as ot
import openturns.viewer as viewer
sampleSize=10
g = ot.SymbolicFunction(["x"], ["0.5*x^2 + sin(2.5*x)"])
xMin = -0.9
xMax = 1.9
X_distr = ot.Uniform(xMin, xMax)
X = ot.LHSExperiment(X_distr, sampleSize, False, False).generate()
Y = g(X)

graph = g.draw(xMin, xMax)
view = viewer.View(graph)

This produces the following errror:

NameError                                 Traceback (most recent call last)
Cell In[9], line 7
      5 xMax = 1.9
      6 X_distr = ot.Uniform(xMin, xMax)
----> 7 X = ot.LHSExperiment(X_distr, sampleSize, False, False).generate()
      8 Y = g(X)
     10 graph = g.draw(xMin, xMax)

NameError: name 'sampleSize' is not defined

In [10]: 
    ...: 
    ...: import openturns as ot
    ...: import openturns.viewer as viewer
    ...: sampleSize=10
    ...: g = ot.SymbolicFunction(["x"], ["0.5*x^2 + sin(2.5*x)"])
    ...: xMin = -0.9
    ...: xMax = 1.9
    ...: X_distr = ot.Uniform(xMin, xMax)
    ...: X = ot.LHSExperiment(X_distr, sampleSize, False, False).generate()
    ...: Y = g(X)
    ...: 
    ...: graph = g.draw(xMin, xMax)
    ...: view = viewer.View(graph)
    ...: 
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[10], line 12
      9 Y = g(X)
     11 graph = g.draw(xMin, xMax)
---> 12 view = viewer.View(graph)

File ~/miniconda3/envs/kriging3/lib/python3.11/site-packages/openturns/viewer.py:299, 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)
    294 if (graph.getLogScale() == ot.GraphImplementation.LOGY) or (
    295     graph.getLogScale() == ot.GraphImplementation.LOGXY
    296 ):
    297     self._ax[0].set_yscale("log")
--> 299 self._ax[0].grid(b=graph.getGrid())
    301 # use scientific notation on non-log axis
    302 axis_mask = {
    303     ot.GraphImplementation.NONE: "both",
    304     ot.GraphImplementation.LOGX: "y",
    305     ot.GraphImplementation.LOGY: "x",
    306     ot.GraphImplementation.LOGXY: None,
    307 }

File ~/miniconda3/envs/kriging3/lib/python3.11/site-packages/matplotlib/axes/_base.py:3194, in _AxesBase.grid(self, visible, which, axis, **kwargs)
   3192 _api.check_in_list(['x', 'y', 'both'], axis=axis)
   3193 if axis in ['x', 'both']:
-> 3194     self.xaxis.grid(visible, which=which, **kwargs)
   3195 if axis in ['y', 'both']:
   3196     self.yaxis.grid(visible, which=which, **kwargs)

File ~/miniconda3/envs/kriging3/lib/python3.11/site-packages/matplotlib/axis.py:1660, in Axis.grid(self, visible, which, **kwargs)
   1657 if which in ['major', 'both']:
   1658     gridkw['gridOn'] = (not self._major_tick_kw['gridOn']
   1659                         if visible is None else visible)
-> 1660     self.set_tick_params(which='major', **gridkw)
   1661 self.stale = True

File ~/miniconda3/envs/kriging3/lib/python3.11/site-packages/matplotlib/axis.py:932, in Axis.set_tick_params(self, which, reset, **kwargs)
    919 """
    920 Set appearance parameters for ticks, ticklabels, and gridlines.
    921 
   (...)
    929     gridlines.
    930 """
    931 _api.check_in_list(['major', 'minor', 'both'], which=which)
--> 932 kwtrans = self._translate_tick_params(kwargs)
    934 # the kwargs are stored in self._major/minor_tick_kw so that any
    935 # future new ticks will automatically get them
    936 if reset:

File ~/miniconda3/envs/kriging3/lib/python3.11/site-packages/matplotlib/axis.py:1076, in Axis._translate_tick_params(kw, reverse)
   1074 for key in kw_:
   1075     if key not in allowed_keys:
-> 1076         raise ValueError(
   1077             "keyword %s is not recognized; valid keywords are %s"
   1078             % (key, allowed_keys))
   1079 kwtrans.update(kw_)
   1080 return kwtrans

ValueError: keyword grid_b is not recognized; valid keywords are ['size', 'width', 'color', 'tickdir', 'pad', 'labelsize', 'labelcolor', 'zorder', 'gridOn', 'tick1On', 'tick2On', 'label1On', 'label2On', 'length', 'direction', 'left', 'bottom', 'right', 'top', 'labelleft', 'labelbottom', 'labelright', 'labeltop', 'labelrotation', 'grid_agg_filter', 'grid_alpha', 'grid_animated', 'grid_antialiased', 'grid_clip_box', 'grid_clip_on', 'grid_clip_path', 'grid_color', 'grid_dash_capstyle', 'grid_dash_joinstyle', 'grid_dashes', 'grid_data', 'grid_drawstyle', 'grid_figure', 'grid_fillstyle', 'grid_gapcolor', 'grid_gid', 'grid_in_layout', 'grid_label', 'grid_linestyle', 'grid_linewidth', 'grid_marker', 'grid_markeredgecolor', 'grid_markeredgewidth', 'grid_markerfacecolor', 'grid_markerfacecoloralt', 'grid_markersize', 'grid_markevery', 'grid_mouseover', 'grid_path_effects', 'grid_picker', 'grid_pickradius', 'grid_rasterized', 'grid_sketch_params', 'grid_snap', 'grid_solid_capstyle', 'grid_solid_joinstyle', 'grid_transform', 'grid_url', 'grid_visible', 'grid_xdata', 'grid_ydata', 'grid_zorder', 'grid_aa', 'grid_c', 'grid_ds', 'grid_ls', 'grid_lw', 'grid_mec', 'grid_mew', 'grid_mfc', 'grid_mfcalt', 'grid_ms']

Does someone have an idea how I can fix that?

Thanks for your help!

Philipp

1 Like

Hi,
This bug is known, see

and

It has been fixed in OpenTURNS 1.21rc1, and if you can’t upgrade a workaround is to deactivate the grid in your graph before to send it to the viewer:

myGraph.setGrid(False)

Cheers

Régis

1 Like

Hi Régis,
Thank you very much, sorry, I should’ve checked the Github repo more carefully.

Perfect, now everything looks fine!

Best,

Philipp

1 Like