Python matplotlib.pylab.axes() Examples

The following are 6 code examples of matplotlib.pylab.axes(). 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.pylab , or try the search function .
Example #1
Source File: utils.py    From Building-Machine-Learning-Systems-With-Python-Second-Edition with MIT License 6 votes vote down vote up
def plot_confusion_matrix(cm, genre_list, name, title):
    pylab.clf()
    pylab.matshow(cm, fignum=False, cmap='Blues', vmin=0, vmax=1.0)
    ax = pylab.axes()
    ax.set_xticks(range(len(genre_list)))
    ax.set_xticklabels(genre_list)
    ax.xaxis.set_ticks_position("bottom")
    ax.set_yticks(range(len(genre_list)))
    ax.set_yticklabels(genre_list)
    pylab.title(title)
    pylab.colorbar()
    pylab.grid(False)
    pylab.show()
    pylab.xlabel('Predicted class')
    pylab.ylabel('True class')
    pylab.grid(False)
    pylab.savefig(
        os.path.join(CHART_DIR, "confusion_matrix_%s.png" % name), bbox_inches="tight") 
Example #2
Source File: mpl.py    From spotpy with MIT License 6 votes vote down vote up
def __init__(self, rect, wtype, *args, **kwargs):
        """
        Creates a matplotlib.widgets widget
        :param rect: The rectangle of the position [left, bottom, width, height] in relative figure coordinates
        :param wtype: A type from matplotlib.widgets, eg. Button, Slider, TextBox, RadioButtons
        :param args: Positional arguments passed to the widget
        :param kwargs: Keyword arguments passed to the widget and events used for the widget
                       eg. if wtype is Slider, on_changed=f can be used as keyword argument

        """
        self.ax = plt.axes(rect)
        events = {}
        for k in list(kwargs.keys()):
            if k.startswith('on_'):
                events[k] = kwargs.pop(k)
        self.object = wtype(self.ax, *args, **kwargs)
        for k in events:
            if hasattr(self.object, k):
                getattr(self.object, k)(events[k]) 
Example #3
Source File: euclidean.py    From cortex_old with GNU General Public License v3.0 6 votes vote down vote up
def save_images(self, X, imgfile, density=False):
        ax = plt.axes()
        x = X[:, 0]
        y = X[:, 1]
        if density:
            xy = np.vstack([x,y])
            z = scipy.stats.gaussian_kde(xy)(xy)
            ax.scatter(x, y, c=z, marker='o', edgecolor='')
        else:
            ax.scatter(x, y, marker='o', c=range(x.shape[0]),
                        cmap=plt.cm.coolwarm)

        if self.collection is not None:
            self.collection.set_transform(ax.transData)
            ax.add_collection(self.collection)


        ax.text(x[0], y[0], str('start'), transform=ax.transAxes)
        ax.axis([-0.2, 1.2, -0.2, 1.2])
        fig = plt.gcf()

        plt.savefig(imgfile)
        plt.close() 
Example #4
Source File: mpl.py    From spotpy with MIT License 5 votes vote down vote up
def __init__(self, setup):
        """
        Creates the GUI

        :param setup: A spotpy setup
        """
        self.fig = plt.figure(type(setup).__name__)
        self.ax = plt.axes([0.05, 0.1, 0.65, 0.85])
        self.button_run = Widget([0.75, 0.01, 0.1, 0.03], Button, 'Simulate', on_clicked=self.run)
        self.button_clear = Widget([0.87, 0.01, 0.1, 0.03], Button, 'Clear plot', on_clicked=self.clear)
        self.parameter_values = {}
        self.setup = setup
        self.sliders = self._make_widgets()
        self.lines = []
        self.clear() 
Example #5
Source File: plotlib.py    From incubator-sdap-nexus with Apache License 2.0 5 votes vote down vote up
def image2(vals, vmin=None, vmax=None, outFile=None,
           imageWidth=None, imageHeight=None, upOrDown='upper',
           cmap=M.cm.jet, makeFigure=False, **options
          ):
    M.clf()
    M.axes([0, 0, 1, 1])
    if vmin == 'auto': vmin = None
    if vmax == 'auto': vmax = None
    if imageWidth is not None: makeFigure = True
    if cmap is None or cmap == '': cmap = M.cm.jet
    if isinstance(cmap, types.StringType) and cmap != '':
        try:
            cmap = eval('M.cm.' + cmap)
        except:
            cmap = M.cm.jet

    if makeFigure:
        dpi = float(options['dpi'])
        width = float(imageWidth) / dpi
        height = float(imageHeight) / dpi
        f = M.figure(figsize=(width,height)).add_axes([0.1,0.1,0.8,0.8], frameon=True)

    if vmin is not None or vmax is not None: 
        if vmin is None:
            vmin = min(min(vals))
        else:
            vmin = float(vmin)
        if vmax is None:
            vmax = max(max(vals))
        else:
            vmax = float(vmax)
        vrange = vmax - vmin
        levels = N.arange(vmin, vmax, vrange/30.)
    else:
        levels = 30

    M.contourf(vals, levels, cmap=cmap, origin=upOrDown)
    evalKeywordCmds(options)
    if outFile: M.savefig(outFile, **validCmdOptions(options, 'savefig')) 
Example #6
Source File: BarsViz.py    From refinery with MIT License 4 votes vote down vote up
def plotBarsFromHModel(hmodel, Data=None, doShowNow=True, figH=None,
                       compsToHighlight=None, sortBySize=False,
                       width=12, height=3, Ktop=None):
    if Data is None:
        width = width/2
    if figH is None:
      figH = pylab.figure(figsize=(width,height))
    else:
      pylab.axes(figH)
    K = hmodel.allocModel.K
    VocabSize = hmodel.obsModel.comp[0].lamvec.size
    learned_tw = np.zeros( (K, VocabSize) )
    for k in xrange(K):
        lamvec = hmodel.obsModel.comp[k].lamvec 
        learned_tw[k,:] = lamvec / lamvec.sum()
    if sortBySize:
        sortIDs = np.argsort(hmodel.allocModel.Ebeta[:-1])[::-1]
        sortIDs = sortIDs[:Ktop]
        learned_tw = learned_tw[sortIDs] 
    if Data is not None and hasattr(Data, "true_tw"):
        # Plot the true parameters and learned parameters
        pylab.subplot(121)
        pylab.imshow(Data.true_tw, **imshowArgs)
        pylab.colorbar()
        pylab.title('True Topic x Word')
        pylab.subplot(122)
        pylab.imshow(learned_tw,  **imshowArgs)
        pylab.title('Learned Topic x Word')
    else:
        # Plot just the learned parameters
        aspectR = learned_tw.shape[1]/learned_tw.shape[0]
        while imshowArgs['vmax'] > 2 * np.percentile(learned_tw, 97):
          imshowArgs['vmax'] /= 5
        pylab.imshow(learned_tw, aspect=aspectR, **imshowArgs)

    if compsToHighlight is not None:
        ks = np.asarray(compsToHighlight)
        if ks.ndim == 0:
          ks = np.asarray([ks])
        pylab.yticks( ks, ['**** %d' % (k) for k in ks])
    if doShowNow and figH is None:
      pylab.show()