Esempio n. 1
0
class WidgetsWrapper:
    def __init__(self):
        self.widgets = gtk.glade.XML('mpl_with_glade.glade')
        self.widgets.signal_autoconnect(GladeHandlers.__dict__)

        self.figure = Figure(figsize=(8, 6), dpi=72)
        self.axis = Subplot(self.figure, 111)
        self.figure.add_axis(self.axis)
        t = arange(0.0, 3.0, 0.01)
        s = sin(2 * pi * t)
        self.axis.plot(t, s)
        self.axis.set_xlabel('time (s)')
        self.axis.set_ylabel('voltage')

        self.canvas = FigureCanvasGTK(self.figure)  # a gtk.DrawingArea
        self.canvas.show()
        self['vboxMain'].pack_start(self.canvas, gtk.TRUE, gtk.TRUE)
        self['vboxMain'].show()

        # below is optional if you want the navigation toolbar
        self.navToolbar = NavigationToolbar(self.canvas, self['windowMain'])
        self.navToolbar.lastDir = '/var/tmp/'
        self['vboxMain'].pack_start(self.navToolbar)
        self.navToolbar.show()

        sep = gtk.HSeparator()
        sep.show()
        self['vboxMain'].pack_start(sep, gtk.TRUE, gtk.TRUE)

        self['vboxMain'].reorder_child(self['buttonClickMe'], -1)

    def __getitem__(self, key):
        return self.widgets.get_widget(key)
Esempio n. 2
0
class WidgetsWrapper:
    def __init__(self):
        self.widgets = gtk.glade.XML('mpl_with_glade.glade')
        self.widgets.signal_autoconnect(GladeHandlers.__dict__)

        self.figure = Figure(figsize=(8,6), dpi=72)
        self.axis = Subplot(self.figure, 111)
        self.figure.add_axis(self.axis)
        t = arange(0.0,3.0,0.01)
        s = sin(2*pi*t)
        self.axis.plot(t,s)
        self.axis.set_xlabel('time (s)')
        self.axis.set_ylabel('voltage')

        self.canvas = FigureCanvasGTK(self.figure) # a gtk.DrawingArea
        self.canvas.show()
        self['vboxMain'].pack_start(self.canvas, gtk.TRUE, gtk.TRUE)
        self['vboxMain'].show()
        
        # below is optional if you want the navigation toolbar
        self.navToolbar = NavigationToolbar(self.canvas, self['windowMain'])
        self.navToolbar.lastDir = '/var/tmp/'
        self['vboxMain'].pack_start(self.navToolbar)
        self.navToolbar.show()

        sep = gtk.HSeparator()
        sep.show()
        self['vboxMain'].pack_start(sep, gtk.TRUE, gtk.TRUE)


        self['vboxMain'].reorder_child(self['buttonClickMe'],-1)

    def __getitem__(self, key):
        return self.widgets.get_widget(key)
Esempio n. 3
0
    def tsplot(self,*parms,**kwargs):
        """Plots the data parsed in argument.
This command accepts the same keywords as `matplotlib.plot`."""
#        parms = tuple(list(parms) + kwargs.pop('series',None))
#        print "Parameters: %s - %i" % (parms, len(parms))
#        print "OPtions: %s - %i" % (kwargs, len(kwargs))
        parms = self._check_plot_params(*parms)
        self.legendlabels.append(kwargs.get('label',None))
        Subplot.plot(self, *parms,**kwargs)
        self.format_dateaxis()
Esempio n. 4
0
def plot_chem_shift_dist(title,residues, amino_acids):
    three_lets = [aa.three_let for aa in amino_acids]
    nuclei = ['CO', 'CA', 'CB', 'CG', 'CG1', 'CG2',
              'CD', 'CD1', 'CD2', 'CE', 'CE1', 'CE2',
              'CE3', 'CZ', 'CZ2', 'CZ3', 'CH2']
    colors = ['b','g','r','c','c','c',
              'm','m','m','y','y','y',
              'y','gray','gray','gray','k']
    
    means, stds = data_array(amino_acids, nuclei)
    fig = pl.figure()
    ax = Subplot(fig,111)
    ax = pl.gca()
    fig.add_subplot(ax)
    
    x = means
#    print nan_to_num(x)
    y = ones(x.shape)
    for i in range(0,x.shape[0]):
        y[i]*=i
        
    for j in range(0,x.shape[1]):
        ax.errorbar(x.T[j], y.T[j], xerr=nan_to_num(stds.T[j]), 
                    linestyle='None',marker='o', color=colors[j], 
                    label=(nuclei[j]), linewidth=4, capsize=20)
    
    for r in residues:
        x = ones_like(means)*nan
        name = r.name
        shifts, atoms = r.get_carbons(previous=False)
        for shift,atom in zip(shifts,atoms):
            if atom in nuclei:
                j = nuclei.index(atom)
#                if name != "NAA":
#                    name = one2Three(r.name[0])
                i = three_lets.index(name)
                x[i][j] = shift
        for j in range(0,x.shape[1]):
            ax.plot(x.T[j],y.T[j], marker="x",linestyle="None", color=colors[j],markersize=15)
    
    pl.yticks(arange(0,20), three_lets)
    pl.ylim(-1,20)
    pl.title('Verteilung chemischer Verschiebungen\n %s'%title)
    pl.ylabel('Aminosaeure')
    pl.xlabel('ppm')
    pl.rcParams.update({'font.size': 22})
    # Shink current axis by 20%
    box = ax.get_position()
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
    
    # Put a legend to the right of the current axis
    ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
    pl.show()
Esempio n. 5
0
def _modify_axis(
    ax: Subplot,
    time: list,
    data: list,
    *,
    color: str,
    label: str,
):
    ax.set_ylabel(label, color=color)
    if isinstance(time[0], list):
        for plot in zip(time, data):
            ax.plot(*plot)
    else:
        ax.plot(time, data, color=color)
    ax.tick_params(axis='y', labelcolor=color)

    ax.xaxis.set_major_locator(mdates.MinuteLocator(interval=5))
    ax.xaxis.set_major_formatter(mdates.DateFormatter("%H:%M"))
Esempio n. 6
0
    def tsplot(self, *args, **kwargs):
        """
    Plots the data parsed in argument to the current axes.
    This command accepts the same optional keywords as :func:`matplotlib.pyplot.plot`.

    The argument ``args`` is a variable length argument, allowing for multiple
    data to be plotted at once. Acceptable combinations are:

    No arguments or a format string:
       The time series associated with the subplot is plotted with the given
       format.
       If no format string is given, the default format is used instead.
       For example, to plot the underlying time series with the default format,
       use:

          >>> tsplot()

       To plot the underlying time series with a red solid line, use the command:

          >>> tsplot('r-')

    a :class:`~scikits.timeseries.TimeSeries` object or one of its subclass
    with or without a format string:
       The given time series is plotted with the given format.
       If no format string is given, the default format is used instead.

    an array or sequence, with or without a format string:
       The data is plotted with the given format
       using the :attr:`~TimeSeriesPlot.xdata` attribute of the plot as abscissae.

    two arrays or sequences, with or without a format string:
       The data are plotted with the given format, using the first array as
       abscissae and the second as ordinates.


    Parameters
    ----------
    args : var
        Sequence of arguments, as described previously.
    kwargs : var
        Optional parameters.
        The same parameters are accepted as for :meth:`matplotlib.axes.Subplot.plot`.

        """
        args = self._check_plot_params(*args)
        self.legendlabels.append(kwargs.get("label", None))
        plotted = Subplot.plot(self, *args, **kwargs)
        self.format_dateaxis()

        # when adding a right axis (using add_yaxis), for some reason the
        # x axis limits don't get properly set. This gets around the problem
        xlim = self.get_xlim()
        if xlim[0] == 0.0 and xlim[1] == 1.0:
            # if xlim still at default values, autoscale the axis
            self.autoscale_view()
        self.reset_datelimits()
        return plotted
Esempio n. 7
0
    def tsplot(self, *args, **kwargs):
        """
    Plots the data parsed in argument to the current axes.
    This command accepts the same optional keywords as :func:`matplotlib.pyplot.plot`.

    The argument ``args`` is a variable length argument, allowing for multiple
    data to be plotted at once. Acceptable combinations are:

    No arguments or a format string:
       The time series associated with the subplot is plotted with the given
       format.
       If no format string is given, the default format is used instead.
       For example, to plot the underlying time series with the default format,
       use:

          >>> tsplot()

       To plot the underlying time series with a red solid line, use the command:

          >>> tsplot('r-')

    a :class:`~scikits.timeseries.TimeSeries` object or one of its subclass
    with or without a format string:
       The given time series is plotted with the given format.
       If no format string is given, the default format is used instead.

    an array or sequence, with or without a format string:
       The data is plotted with the given format
       using the :attr:`~TimeSeriesPlot.xdata` attribute of the plot as abscissae.

    two arrays or sequences, with or without a format string:
       The data are plotted with the given format, using the first array as
       abscissae and the second as ordinates.


    Parameters
    ----------
    args : var
        Sequence of arguments, as described previously.
    kwargs : var
        Optional parameters.
        The same parameters are accepted as for :meth:`matplotlib.axes.Subplot.plot`.

        """
        args = self._check_plot_params(*args)
        self.legendlabels.append(kwargs.get('label', None))
        plotted = Subplot.plot(self, *args, **kwargs)
        self.format_dateaxis()

        # when adding a right axis (using add_yaxis), for some reason the
        # x axis limits don't get properly set. This gets around the problem
        xlim = self.get_xlim()
        if xlim[0] == 0.0 and xlim[1] == 1.0:
            # if xlim still at default values, autoscale the axis
            self.autoscale_view()
        self.reset_datelimits()
        return plotted
Esempio n. 8
0
    def convergence(self, axis: Subplot) -> List[Line2D]:
        """Plot the convergence of the PLSA run.

        The quantity to be minimized is the Kullback-Leibler divergence
        between the original document-word matrix and its approximation
        given by the (conditional) PLSA factorization.

        Parameters
        ----------
        axis: Subplot
            The matplotlib axis to plot into.

        Returns
        -------
        list of Line2D
            The line object plotted into the given axis.

        """
        axis.set(xlabel='Iteration', ylabel='Kullback-Leibler divergence')
        return axis.plot(self.__convergence)
Esempio n. 9
0
from matplotlib.axes import Subplot
import Numeric as numpy
import gtk

win = gtk.Window()
win.set_name("Embedding in GTK")
win.connect("destroy", gtk.mainquit)
win.set_border_width(5)

vbox = gtk.VBox(spacing=3)
win.add(vbox)
vbox.show()

f = Figure(figsize=(5,4), dpi=100)
a = Subplot(f, 111)
t = numpy.arange(0.0,3.0,0.01)
s = numpy.sin(2*numpy.pi*t)

a.plot(t,s)
f.add_axis(a)
f.show()
vbox.pack_start(f)

button = gtk.Button('Quit')
button.connect('clicked', lambda b: gtk.mainquit())
button.show()
vbox.pack_start(button)

win.show()
gtk.mainloop()
Esempio n. 10
0
win = gtk.Window()
win.set_name("Embedding in GTK")
win.connect("destroy", gtk.mainquit)
win.set_border_width(5)

vbox = gtk.VBox(spacing=3)
win.add(vbox)
vbox.show()

fig = Figure(figsize=(5,4), dpi=100)

ax = Subplot(fig, 111)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)

ax.plot(t,s)
ax.set_title('click on line or text')
fig.add_axis(ax)

canvas = PickerCanvas(fig)
canvas.show()
vbox.pack_start(canvas)

toolbar = NavigationToolbar(canvas, win)
toolbar.show()
vbox.pack_start(toolbar, gtk.FALSE, gtk.FALSE)


win.show()
gtk.mainloop()
Esempio n. 11
0
win = gtk.Window()
win.set_name("Embedding in GTK")
win.connect("destroy", gtk.mainquit)
win.set_border_width(5)

vbox = gtk.VBox(spacing=3)
win.add(vbox)
vbox.show()

fig = Figure(figsize=(5,4), dpi=100)
ax = Subplot(fig, 111)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)

ax.plot(t,s)
fig.add_axis(ax)

canvas = FigureCanvasGTK(fig)  # a gtk.DrawingArea
canvas.show()
vbox.pack_start(canvas)


toolbar = NavigationToolbar(canvas, win)
toolbar.show()
vbox.pack_start(toolbar, gtk.FALSE, gtk.FALSE)

buttonQuit = gtk.Button('Quit')
buttonQuit.connect('clicked', gtk.mainquit)
buttonQuit.show()
vbox.pack_start(buttonQuit)
Esempio n. 12
0
import gtk

win = gtk.Window()
win.set_name("Embedding in GTK")
win.connect("destroy", gtk.mainquit)
win.set_border_width(5)

vbox = gtk.VBox(spacing=3)
win.add(vbox)
vbox.show()

f = Figure(figsize=(5, 4), dpi=100)
a = Subplot(f, 111)
t = arange(0.0, 3.0, 0.01)
s = sin(2 * pi * t)

a.plot(t, s)
f.add_axis(a)

canvas = FigureCanvasGTK(f)  # a gtk.DrawingArea
canvas.show()
vbox.pack_start(canvas)

button = gtk.Button('Quit')
button.connect('clicked', lambda b: gtk.mainquit())
button.show()
vbox.pack_start(button)

win.show()
gtk.mainloop()
Esempio n. 13
0
import matplotlib
matplotlib.use('GD')
from matplotlib.backends.backend_gd import Figure, show
from matplotlib.axes import Subplot

dpi = 100
figsize = (5, 5)
f = Figure(figsize, dpi)
a = Subplot(f, 111)
f.add_axis(a)
l = a.plot([1,2,3], [4,5,6])

a.set_xlabel('time (s)')
a.set_ylabel('Signal 2')
f.print_figure('gdtest', dpi)
show()

Esempio n. 14
0
import matplotlib
matplotlib.use('GD')
from matplotlib.backends.backend_gd import Figure, show
from matplotlib.axes import Subplot

dpi = 100
figsize = (5, 5)
f = Figure(figsize, dpi)
a = Subplot(f, 111)
f.add_axis(a)
l = a.plot([1, 2, 3], [4, 5, 6])

a.set_xlabel('time (s)')
a.set_ylabel('Signal 2')
f.print_figure('gdtest', dpi)
show()