def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm) assert len(w) == 0
def test_normalize_kwargs_fail(inp, kwargs_to_norm): with pytest.raises(TypeError): cbook.normalize_kwargs(inp, **kwargs_to_norm)
def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm): with cbook._suppress_matplotlib_deprecation_warning(): # No other warning should be emitted. assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm)
def _kwarg_norm_helper(inp, expected, kwargs_to_norm, warn_count=0): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm) assert len(w) == warn_count
def test_normalize_kwargs_fail(inp, kwargs_to_norm): with pytest.raises(TypeError), \ cbook._suppress_matplotlib_deprecation_warning(): cbook.normalize_kwargs(inp, **kwargs_to_norm)
def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm, recwarn): with cbook._suppress_matplotlib_deprecation_warning(): assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm) assert len(recwarn) == 0
def __init__(self, ax, onselect, direction, minspan=0, useblit=False, props=None, onmove_callback=None, interactive=False, button=None, handle_props=None, grab_range=10, drag_from_anywhere=False, ignore_event_outside=False, snap_values=None): super().__init__(ax, onselect, useblit=useblit, button=button) if props is None: props = dict(facecolor='red', alpha=0.5) props['animated'] = self.useblit self.direction = direction self.visible = True self._extents_on_press = None # self._pressv is deprecated and we don't use it internally anymore # but we maintain it until it is removed self._pressv = None self._props = props self.onmove_callback = onmove_callback self.minspan = minspan self.grab_range = grab_range self._interactive = interactive self._edge_handles = None self.drag_from_anywhere = drag_from_anywhere self.ignore_event_outside = ignore_event_outside self.snap_values = snap_values # Reset canvas so that `new_axes` connects events. self.canvas = None self.new_axes(ax) # Setup handles if handle_props is None: handle_props = {} self._handle_props = { 'color': props.get('facecolor', 'r'), **cbook.normalize_kwargs(handle_props, Line2D._alias_map) } if self._interactive: self._edge_order = ['min', 'max'] self._setup_edge_handles(self._handle_props) self._active_handle = None # prev attribute is deprecated but we still need to maintain it self._prev = (0, 0)
def triplot(ax, *args, **kwargs): """ Draw a unstructured triangular grid as lines and/or markers. The triangulation to plot can be specified in one of two ways; either:: triplot(triangulation, ...) where triangulation is a `.Triangulation` object, or :: triplot(x, y, ...) triplot(x, y, triangles, ...) triplot(x, y, triangles=triangles, ...) triplot(x, y, mask=mask, ...) triplot(x, y, triangles, mask=mask, ...) in which case a Triangulation object will be created. See `.Triangulation` for a explanation of these possibilities. The remaining args and kwargs are the same as for `~.Axes.plot`. Returns ------- lines : `~matplotlib.lines.Line2D` The drawn triangles edges. markers : `~matplotlib.lines.Line2D` The drawn marker nodes. """ import matplotlib.axes tri, args, kwargs = Triangulation.get_from_args_and_kwargs(*args, **kwargs) x, y, edges = (tri.x, tri.y, tri.edges) # Decode plot format string, e.g., 'ro-' fmt = args[0] if args else "" linestyle, marker, color = matplotlib.axes._base._process_plot_format(fmt) # Insert plot format string into a copy of kwargs (kwargs values prevail). kw = cbook.normalize_kwargs(kwargs, mlines.Line2D) for key, val in zip(('linestyle', 'marker', 'color'), (linestyle, marker, color)): if val is not None: kw.setdefault(key, val) # Draw lines without markers. # Note 1: If we drew markers here, most markers would be drawn more than # once as they belong to several edges. # Note 2: We insert nan values in the flattened edges arrays rather than # plotting directly (triang.x[edges].T, triang.y[edges].T) # as it considerably speeds-up code execution. linestyle = kw['linestyle'] kw_lines = { **kw, 'marker': 'None', # No marker to draw. 'zorder': kw.get('zorder', 1), # Path default zorder is used. } if linestyle not in [None, 'None', '', ' ']: tri_lines_x = np.insert(x[edges], 2, np.nan, axis=1) tri_lines_y = np.insert(y[edges], 2, np.nan, axis=1) tri_lines = ax.plot(tri_lines_x.ravel(), tri_lines_y.ravel(), **kw_lines) else: tri_lines = ax.plot([], [], **kw_lines) # Draw markers separately. marker = kw['marker'] kw_markers = { **kw, 'linestyle': 'None', # No line to draw. } if marker not in [None, 'None', '', ' ']: tri_markers = ax.plot(x, y, **kw_markers) else: tri_markers = ax.plot([], [], **kw_markers) return tri_lines + tri_markers
def triplot(ax, *args, **kwargs): """ Draw an unstructured triangular grid as lines and/or markers. Call signatures:: triplot(triangulation, ...) triplot(x, y, [triangles], *, [mask=mask], ...) The triangular grid can be specified either by passing a `.Triangulation` object as the first parameter, or by passing the points *x*, *y* and optionally the *triangles* and a *mask*. If neither of *triangulation* or *triangles* are given, the triangulation is calculated on the fly. Parameters ---------- triangulation : `.Triangulation` An already created triangular grid. x, y, triangles, mask Parameters defining the triangular grid. See `.Triangulation`. This is mutually exclusive with specifying *triangulation*. other_parameters All other args and kwargs are forwarded to `~.Axes.plot`. Returns ------- lines : `~matplotlib.lines.Line2D` The drawn triangles edges. markers : `~matplotlib.lines.Line2D` The drawn marker nodes. """ import matplotlib.axes tri, args, kwargs = Triangulation.get_from_args_and_kwargs(*args, **kwargs) x, y, edges = (tri.x, tri.y, tri.edges) # Decode plot format string, e.g., 'ro-' fmt = args[0] if args else "" linestyle, marker, color = matplotlib.axes._base._process_plot_format(fmt) # Insert plot format string into a copy of kwargs (kwargs values prevail). kw = cbook.normalize_kwargs(kwargs, mlines.Line2D) for key, val in zip(('linestyle', 'marker', 'color'), (linestyle, marker, color)): if val is not None: kw.setdefault(key, val) # Draw lines without markers. # Note 1: If we drew markers here, most markers would be drawn more than # once as they belong to several edges. # Note 2: We insert nan values in the flattened edges arrays rather than # plotting directly (triang.x[edges].T, triang.y[edges].T) # as it considerably speeds-up code execution. linestyle = kw['linestyle'] kw_lines = { **kw, 'marker': 'None', # No marker to draw. 'zorder': kw.get('zorder', 1), # Path default zorder is used. } if linestyle not in [None, 'None', '', ' ']: tri_lines_x = np.insert(x[edges], 2, np.nan, axis=1) tri_lines_y = np.insert(y[edges], 2, np.nan, axis=1) tri_lines = ax.plot(tri_lines_x.ravel(), tri_lines_y.ravel(), **kw_lines) else: tri_lines = ax.plot([], [], **kw_lines) # Draw markers separately. marker = kw['marker'] kw_markers = { **kw, 'linestyle': 'None', # No line to draw. } if marker not in [None, 'None', '', ' ']: tri_markers = ax.plot(x, y, **kw_markers) else: tri_markers = ax.plot([], [], **kw_markers) return tri_lines + tri_markers