Python matplotlib.lines() Examples

The following are 30 code examples of matplotlib.lines(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib , or try the search function .
Example #1
Source File: _base.py    From GraphicDesignPatternByPython with MIT License 6 votes vote down vote up
def get_children(self):
        """return a list of child artists"""
        children = []
        children.extend(self.collections)
        children.extend(self.patches)
        children.extend(self.lines)
        children.extend(self.texts)
        children.extend(self.artists)
        children.extend(self.spines.values())
        children.append(self.xaxis)
        children.append(self.yaxis)
        children.append(self.title)
        children.append(self._left_title)
        children.append(self._right_title)
        children.extend(self.tables)
        children.extend(self.images)
        children.extend(self.child_axes)

        if self.legend_ is not None:
            children.append(self.legend_)
        children.append(self.patch)

        return children 
Example #2
Source File: pyplot.py    From Computable with MIT License 6 votes vote down vote up
def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None,
               norm=None, arrowsize=1, arrowstyle='-|>', minlength=0.1,
               transform=None, hold=None):
    ax = gca()
    # allow callers to override the hold state by passing hold=True|False
    washold = ax.ishold()

    if hold is not None:
        ax.hold(hold)
    try:
        ret = ax.streamplot(x, y, u, v, density=density, linewidth=linewidth,
                            color=color, cmap=cmap, norm=norm,
                            arrowsize=arrowsize, arrowstyle=arrowstyle,
                            minlength=minlength, transform=transform)
        draw_if_interactive()
    finally:
        ax.hold(washold)
    sci(ret.lines)
    return ret

# This function was autogenerated by boilerplate.py.  Do not edit as
# changes will be lost 
Example #3
Source File: backend_gtk.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def show(self):
        'populate the combo box'
        self._updateson = False
        # flush the old
        cbox = self.cbox_lineprops
        for i in range(self._lastcnt-1,-1,-1):
            cbox.remove_text(i)

        # add the new
        for line in self.lines:
            cbox.append_text(line.get_label())
        cbox.set_active(0)

        self._updateson = True
        self._lastcnt = len(self.lines)
        self.dlg.show() 
Example #4
Source File: backend_gtk3.py    From Computable with MIT License 6 votes vote down vote up
def show(self):
        'populate the combo box'
        self._updateson = False
        # flush the old
        cbox = self.cbox_lineprops
        for i in range(self._lastcnt-1,-1,-1):
            cbox.remove_text(i)

        # add the new
        for line in self.lines:
            cbox.append_text(line.get_label())
        cbox.set_active(0)

        self._updateson = True
        self._lastcnt = len(self.lines)
        self.dlg.show() 
Example #5
Source File: backend_gtk.py    From Computable with MIT License 6 votes vote down vote up
def show(self):
        'populate the combo box'
        self._updateson = False
        # flush the old
        cbox = self.cbox_lineprops
        for i in range(self._lastcnt-1,-1,-1):
            cbox.remove_text(i)

        # add the new
        for line in self.lines:
            cbox.append_text(line.get_label())
        cbox.set_active(0)

        self._updateson = True
        self._lastcnt = len(self.lines)
        self.dlg.show() 
Example #6
Source File: backend_gtk3.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def show(self):
        'populate the combo box'
        self._updateson = False
        # flush the old
        cbox = self.cbox_lineprops
        for i in range(self._lastcnt-1,-1,-1):
            cbox.remove_text(i)

        # add the new
        for line in self.lines:
            cbox.append_text(line.get_label())
        cbox.set_active(0)

        self._updateson = True
        self._lastcnt = len(self.lines)
        self.dlg.show() 
Example #7
Source File: _base.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def add_line(self, line):
        """
        Add a :class:`~matplotlib.lines.Line2D` to the list of plot
        lines

        Returns the line.
        """
        self._set_artist_props(line)
        if line.get_clip_path() is None:
            line.set_clip_path(self.patch)

        self._update_line_limits(line)
        if not line.get_label():
            line.set_label('_line%d' % len(self.lines))
        self.lines.append(line)
        line._remove_method = self.lines.remove
        self.stale = True
        return line 
Example #8
Source File: pyplot.py    From GraphicDesignPatternByPython with MIT License 6 votes vote down vote up
def streamplot(
        x, y, u, v, density=1, linewidth=None, color=None, cmap=None,
        norm=None, arrowsize=1, arrowstyle='-|>', minlength=0.1,
        transform=None, zorder=None, start_points=None, maxlength=4.0,
        integration_direction='both', *, data=None):
    __ret = gca().streamplot(
        x=x, y=y, u=u, v=v, density=density, linewidth=linewidth,
        color=color, cmap=cmap, norm=norm, arrowsize=arrowsize,
        arrowstyle=arrowstyle, minlength=minlength,
        transform=transform, zorder=zorder, start_points=start_points,
        maxlength=maxlength,
        integration_direction=integration_direction, data=data)
    sci(__ret.lines)
    return __ret

# Autogenerated by boilerplate.py.  Do not edit as changes will be lost. 
Example #9
Source File: pyplot.py    From matplotlib-4-abaqus with MIT License 6 votes vote down vote up
def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None,
               norm=None, arrowsize=1, arrowstyle='-|>', minlength=0.1,
               transform=None, hold=None):
    ax = gca()
    # allow callers to override the hold state by passing hold=True|False
    washold = ax.ishold()

    if hold is not None:
        ax.hold(hold)
    try:
        ret = ax.streamplot(x, y, u, v, density=density, linewidth=linewidth,
                            color=color, cmap=cmap, norm=norm,
                            arrowsize=arrowsize, arrowstyle=arrowstyle,
                            minlength=minlength, transform=transform)
        draw_if_interactive()
    finally:
        ax.hold(washold)
    sci(ret.lines)
    return ret

# This function was autogenerated by boilerplate.py.  Do not edit as
# changes will be lost 
Example #10
Source File: segment.py    From COCO-Style-Dataset-Generator-GUI with Apache License 2.0 6 votes vote down vote up
def reset(self, event):

        if not self.click_id:
            self.click_id = fig.canvas.mpl_connect('button_press_event', self.onclick)
        #print (len(self.lines))
        #print (len(self.circles))
        if len(self.points)>5:
            for line in self.lines:
                line.pop(0).remove()
            for circle in self.circles:
                circle.remove()
            self.lines, self.circles = [], []
            self.p.remove()
            self.prev = self.p = None
            self.points = []
        #print (len(self.lines))
        #print (len(self.circles)) 
Example #11
Source File: segment.py    From COCO-Style-Dataset-Generator-GUI with Apache License 2.0 6 votes vote down vote up
def submit(self, event):

        if not self.right_click:
            print ('Right click before submit is a must!!')
        else:

            self.text+=self.radio.value_selected+'\n'+'%.2f'%self.find_poly_area()+'\n'+self.print_points()+'\n\n'
            self.right_click = False
            #print (self.points)

            self.lines, self.circles = [], []
            self.click_id = fig.canvas.mpl_connect('button_press_event', self.onclick)

            self.polys.append(Polygon(self.points_to_polygon(), closed=True, color=np.random.rand(3), alpha=0.4, fill=True))
            if self.submit_p:
                self.submit_p.remove()
            self.submit_p = PatchCollection(self.polys, cmap=matplotlib.cm.jet, alpha=0.4)
            self.ax.add_collection(self.submit_p)
            self.points = [] 
Example #12
Source File: lineplot.py    From PyXRF with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _color_config(self):
        self.plot_style = {
            'experiment': {'color': 'blue', 'linestyle': '',
                           'marker': '.', 'label': self.exp_data_label},
            'background': {'color': 'indigo', 'marker': '+',
                           'markersize': 1, 'label': 'background'},
            'emission_line': {'color': 'black', 'linewidth': 2},
            'roi_line': {'color': 'red', 'linewidth': 2},
            'k_line': {'color': 'green', 'label': 'k lines'},
            'l_line': {'color': 'magenta', 'label': 'l lines'},
            'm_line': {'color': 'brown', 'label': 'm lines'},
            'compton': {'color': 'darkcyan', 'linewidth': 1.5, 'label': 'compton'},
            'elastic': {'color': 'purple', 'label': 'elastic'},
            'escape': {'color': 'darkblue', 'label': 'escape'},
            'pileup': {'color': 'darkgoldenrod', 'label': 'pileup'},
            'userpeak': {'color': 'orange', 'label': 'userpeak'},
            # 'auto_fit': {'color': 'black', 'label': 'auto fitted', 'linewidth': 2.5},
            'fit': {'color': 'red', 'label': 'fit', 'linewidth': 2.5},
            'residual': {'color': 'black', 'label': 'residual', 'linewidth': 2.0}
        } 
Example #13
Source File: lineplot.py    From PyXRF with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def plot_emission_line(self):
        """
        Plot emission line and escape peaks associated with given lines.
        The value of self.max_v is needed in this function in order to plot
        the relative height of each emission line.
        """
        while(len(self.eline_obj)):
            self.eline_obj.pop().remove()

        escape_e = self.escape_e

        if len(self.elist):
            for i in range(len(self.elist)):
                eline, = self._ax.plot([self.elist[i][0], self.elist[i][0]],
                                       [0, self.elist[i][1]*self.max_v],
                                       color=self.plot_style['emission_line']['color'],
                                       linewidth=self.plot_style['emission_line']['linewidth'])
                self.eline_obj.append(eline)
                if self.plot_escape_line and self.elist[i][0] > escape_e:
                    eline, = self._ax.plot([self.elist[i][0]-escape_e,
                                            self.elist[i][0]-escape_e],
                                           [0, self.elist[i][1]*self.max_v],
                                           color=self.plot_style['escape']['color'],
                                           linewidth=self.plot_style['emission_line']['linewidth'])
                    self.eline_obj.append(eline) 
Example #14
Source File: _base.py    From GraphicDesignPatternByPython with MIT License 6 votes vote down vote up
def add_line(self, line):
        """
        Add a :class:`~matplotlib.lines.Line2D` to the list of plot
        lines

        Returns the line.
        """
        self._set_artist_props(line)
        if line.get_clip_path() is None:
            line.set_clip_path(self.patch)

        self._update_line_limits(line)
        if not line.get_label():
            line.set_label('_line%d' % len(self.lines))
        self.lines.append(line)
        line._remove_method = self.lines.remove
        self.stale = True
        return line 
Example #15
Source File: change_tracker.py    From pylustrator with GNU General Public License v3.0 6 votes vote down vote up
def save(self):
        """ save the changes to the .py file """
        header = [getReference(self.figure) + ".ax_dict = {ax.get_label(): ax for ax in " + getReference(
            self.figure) + ".axes}", "import matplotlib as mpl"]

        # block = getTextFromFile(header[0], self.stack_position)
        output = ["#% start: automatic generated code from pylustrator"]
        # add the lines from the header
        for line in header:
            output.append(line)
        # add all lines from the changes
        for line in self.sorted_changes():
            output.append(line)
            if line.startswith("fig.add_axes"):
                output.append(header[1])
        output.append("#% end: automatic generated code from pylustrator")
        # print("\n".join(output))

        block_id = getReference(self.figure)
        block = getTextFromFile(block_id, stack_position)
        if not block:
            block_id = getReference(self.figure, allow_using_variable_names=False)
            block = getTextFromFile(block_id, stack_position)
        insertTextToFile(output, stack_position, block_id)
        self.saved = True 
Example #16
Source File: backend_gtk.py    From neural-network-animation with MIT License 6 votes vote down vote up
def show(self):
        'populate the combo box'
        self._updateson = False
        # flush the old
        cbox = self.cbox_lineprops
        for i in range(self._lastcnt-1,-1,-1):
            cbox.remove_text(i)

        # add the new
        for line in self.lines:
            cbox.append_text(line.get_label())
        cbox.set_active(0)

        self._updateson = True
        self._lastcnt = len(self.lines)
        self.dlg.show() 
Example #17
Source File: backend_gtk3.py    From neural-network-animation with MIT License 6 votes vote down vote up
def show(self):
        'populate the combo box'
        self._updateson = False
        # flush the old
        cbox = self.cbox_lineprops
        for i in range(self._lastcnt-1,-1,-1):
            cbox.remove_text(i)

        # add the new
        for line in self.lines:
            cbox.append_text(line.get_label())
        cbox.set_active(0)

        self._updateson = True
        self._lastcnt = len(self.lines)
        self.dlg.show() 
Example #18
Source File: pyplot.py    From neural-network-animation with MIT License 6 votes vote down vote up
def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None,
               norm=None, arrowsize=1, arrowstyle='-|>', minlength=0.1,
               transform=None, zorder=1, hold=None):
    ax = gca()
    # allow callers to override the hold state by passing hold=True|False
    washold = ax.ishold()

    if hold is not None:
        ax.hold(hold)
    try:
        ret = ax.streamplot(x, y, u, v, density=density, linewidth=linewidth,
                            color=color, cmap=cmap, norm=norm,
                            arrowsize=arrowsize, arrowstyle=arrowstyle,
                            minlength=minlength, transform=transform,
                            zorder=zorder)
        draw_if_interactive()
    finally:
        ax.hold(washold)
    sci(ret.lines)
    return ret

# This function was autogenerated by boilerplate.py.  Do not edit as
# changes will be lost 
Example #19
Source File: _base.py    From neural-network-animation with MIT License 6 votes vote down vote up
def relim(self, visible_only=False):
        """
        Recompute the data limits based on current artists. If you want to
        exclude invisible artists from the calculation, set
        ``visible_only=True``

        At present, :class:`~matplotlib.collections.Collection`
        instances are not supported.
        """
        # Collections are deliberately not supported (yet); see
        # the TODO note in artists.py.
        self.dataLim.ignore(True)
        self.dataLim.set_points(mtransforms.Bbox.null().get_points())
        self.ignore_existing_data_limits = True

        for line in self.lines:
            if not visible_only or line.get_visible():
                self._update_line_limits(line)

        for p in self.patches:
            if not visible_only or p.get_visible():
                self._update_patch_limits(p) 
Example #20
Source File: _base.py    From neural-network-animation with MIT License 6 votes vote down vote up
def add_line(self, line):
        """
        Add a :class:`~matplotlib.lines.Line2D` to the list of plot
        lines

        Returns the line.
        """
        self._set_artist_props(line)
        if line.get_clip_path() is None:
            line.set_clip_path(self.patch)

        self._update_line_limits(line)
        if not line.get_label():
            line.set_label('_line%d' % len(self.lines))
        self.lines.append(line)
        line._remove_method = lambda h: self.lines.remove(h)
        return line 
Example #21
Source File: _base.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def _update_transScale(self):
        self.transScale.set(
            mtransforms.blended_transform_factory(
                self.xaxis.get_transform(), self.yaxis.get_transform()))
        for line in getattr(self, "lines", []):  # Not set during init.
            try:
                line._transformed_path.invalidate()
            except AttributeError:
                pass 
Example #22
Source File: _base.py    From neural-network-animation with MIT License 5 votes vote down vote up
def grid(self, b=None, which='major', axis='both', **kwargs):
        """
        Turn the axes grids on or off.

        Call signature::

           grid(self, b=None, which='major', axis='both', **kwargs)

        Set the axes grids on or off; *b* is a boolean.  (For MATLAB
        compatibility, *b* may also be a string, 'on' or 'off'.)

        If *b* is *None* and ``len(kwargs)==0``, toggle the grid state.  If
        *kwargs* are supplied, it is assumed that you want a grid and *b*
        is thus set to *True*.

        *which* can be 'major' (default), 'minor', or 'both' to control
        whether major tick grids, minor tick grids, or both are affected.

        *axis* can be 'both' (default), 'x', or 'y' to control which
        set of gridlines are drawn.

        *kwargs* are used to set the grid line properties, e.g.,::

           ax.grid(color='r', linestyle='-', linewidth=2)

        Valid :class:`~matplotlib.lines.Line2D` kwargs are

        %(Line2D)s

        """
        if len(kwargs):
            b = True
        b = _string_to_bool(b)

        if axis == 'x' or axis == 'both':
            self.xaxis.grid(b, which=which, **kwargs)
        if axis == 'y' or axis == 'both':
            self.yaxis.grid(b, which=which, **kwargs) 
Example #23
Source File: _base.py    From neural-network-animation with MIT License 5 votes vote down vote up
def _update_transScale(self):
        self.transScale.set(
            mtransforms.blended_transform_factory(
                self.xaxis.get_transform(), self.yaxis.get_transform()))
        if hasattr(self, "lines"):
            for line in self.lines:
                try:
                    line._transformed_path.invalidate()
                except AttributeError:
                    pass 
Example #24
Source File: _base.py    From neural-network-animation with MIT License 5 votes vote down vote up
def has_data(self):
        """
        Return *True* if any artists have been added to axes.

        This should not be used to determine whether the *dataLim*
        need to be updated, and may not actually be useful for
        anything.
        """
        return (
            len(self.collections) +
            len(self.images) +
            len(self.lines) +
            len(self.patches)) > 0 
Example #25
Source File: pyplot.py    From neural-network-animation with MIT License 5 votes vote down vote up
def figlegend(handles, labels, loc, **kwargs):
    """
    Place a legend in the figure.

    *labels*
      a sequence of strings

    *handles*
      a sequence of :class:`~matplotlib.lines.Line2D` or
      :class:`~matplotlib.patches.Patch` instances

    *loc*
      can be a string or an integer specifying the legend
      location

    A :class:`matplotlib.legend.Legend` instance is returned.

    Example::

      figlegend( (line1, line2, line3),
                 ('label1', 'label2', 'label3'),
                 'upper right' )

    .. seealso::

       :func:`~matplotlib.pyplot.legend`

    """
    l = gcf().legend(handles, labels, loc, **kwargs)
    draw_if_interactive()
    return l


## Figure and Axes hybrid ## 
Example #26
Source File: _base.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def get_lines(self):
        """Return a list of lines contained by the Axes"""
        return cbook.silent_list('Line2D', self.lines) 
Example #27
Source File: _base.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def get_xgridlines(self):
        """Get the x grid lines as a list of `Line2D` instances."""
        return cbook.silent_list('Line2D xgridline',
                                 self.xaxis.get_gridlines()) 
Example #28
Source File: _base.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def get_xticklines(self):
        """Get the x tick lines as a list of `Line2D` instances."""
        return cbook.silent_list('Line2D xtickline',
                                 self.xaxis.get_ticklines()) 
Example #29
Source File: _base.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_xticklines(self):
        """Get the x tick lines as a list of `Line2D` instances."""
        return cbook.silent_list('Line2D xtickline',
                                 self.xaxis.get_ticklines()) 
Example #30
Source File: _base.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_ygridlines(self):
        """Get the y grid lines as a list of `Line2D` instances."""
        return cbook.silent_list('Line2D ygridline',
                                 self.yaxis.get_gridlines())