Exemple #1
0
if __name__ == '__main__':

    from datavyz import ge

    # LOADING THE DATA
    from sklearn.datasets import load_breast_cancer
    data = load_breast_cancer()

    # PERFORMING PCA
    from sklearn.decomposition import PCA as sklPCA
    pca = sklPCA(n_components=4)
    pca.fit_transform(data['data'])

    # PLOT
    fig, AX = ge.components_plot(pca.components_)
    ge.savefig(fig, 'docs/components-plot.png')
    ge.show()

    from sklearn.datasets import load_iris
    dataset = load_iris()
    fig, ax = ge.parallel_plot(
        dataset['data'],
        SET_OF_LABELS=[
            'sepal length\n(cm)', 'sepal width\n(cm)', 'petal length\n(cm)',
            'petal width\n(cm)'
        ],
        COLORS=[ge.viridis(x / 2) for x in dataset['target']])
    for i, name in enumerate(dataset['target_names']):
        ge.annotate(ax,
                    name, ((i + 1) / 3., 1.1),
                    color=ge.viridis(i / 2),
                               xlim=LIMS[i],
                               ylim=LIMS[j],
                               num_xticks=3,
                               num_yticks=3,
                               yticks_labels=[],
                               xticks_labels=[])

    graph.bar_legend(fig,
                     inset=inset,
                     X=np.arange(len(significance)+1),
                     colormap=mymap,\
                     ticks_labels=['n.s.', '$<$0.1', '$<$0.02', '$<$0.001'],
                     label='Significance \n \n (p, Pearson correl.)')

    return fig


if __name__ == '__main__':

    from datavyz import ge

    # building random data
    data = {}
    for i in range(5):
        data['feature_%s' % (i + 1)] = np.random.randn(30)

    # plot
    fig = ge.cross_correl_plot(data, features=list(data.keys())[:7])

    ge.savefig(fig, 'docs/cross-correl.png')
Exemple #3
0
    
    a = (1-SCALE['left']-SCALE['right'])/x_plots-SCALE['wspace']
    a0 = (1-SCALE0['left']-SCALE0['right'])/x_plots-SCALE0['wspace']
    b = (1-SCALE['top']-SCALE['bottom'])/y_plots-SCALE['hspace']
    b0 = (1-SCALE0['top']-SCALE0['bottom'])/y_plots-SCALE0['hspace']
    return {
        'figsize':(\
            A0_format['width']*A0_ratio*x_plots,
                   A0_format['height']*A0_ratio*y_plots*height_to_width)}



if __name__=='__main__':

    from datavyz import ge

    fig, ax = ge.figure(figsize=(1.2,1), left=1., right=4.)
    ax2 = ax.twinx()
    ax.plot(np.log10(np.logspace(-2.2,3,100)), np.exp(np.random.randn(100)), 'o', ms=2, color=ge.blue)
    ax2.plot(np.log10(np.logspace(-2,3,100)), np.exp(np.random.randn(100)), 'o', ms=1, color=ge.red)
    ge.set_plot(ax2, ['right'],
                yscale='log',
                ylabel='blabla',
                # yticks_rotation=20, size='x-small',
                tck_outward=2, ycolor=ge.red)
    ge.set_plot(ax, ycolor=ge.blue, xcolor='k',
                yscale='log', xscale='already-log10', ylabel='blabal', 
                tck_outward=2, xlabel='trying', ylabelpad=-5)
    ge.savefig(fig, 'docs/twin-log-scale.png')
    ge.show()
Exemple #4
0
    return fig, ax, pval


if __name__ == '__main__':

    from datavyz import ge

    # fig1, _ = ge.unrelated_samples_two_conditions_comparison(\
    #     np.random.randn(10)+1.4, np.random.randn(12)+1.4,
    #     xticks_labels=['$\||$cc($V_m$,$V_{ext}$)$\||$', '$cc(V_m,pLFP)$'],
    #     xticks_rotation=75)

    fig, ax, pval = ge.related_samples_two_conditions_comparison(
        np.random.randn(10) + 2.,
        np.random.randn(10) + 2.,
        xticks_labels=['Ctrl', 'Test'],
        xticks_rotation=45)

    ge.savefig(fig, 'docs/related-samples.png')

    fig, ax, pval = ge.unrelated_samples_two_conditions_comparison(
        np.random.randn(10) + 2.,
        np.random.randn(10) + 2.,
        xticks_labels=['Ctrl', 'Test'],
        xticks_rotation=45)
    ge.savefig(fig, 'docs/unrelated-samples.png')

    # # ge.bar(np.random.randn(5), yerr=.3*np.random.randn(5), bottom=-3, COLORS=ge.colors[:5])
    ge.show()
Exemple #5
0
                        ms=ms,
                        elinewidth=elw,
                        label=label)
    else:
        for x, y, sx, sy, c, label in zip(X, Y, sX, sY, COLORS, LABELS):
            ax.errorbar(x,
                        y,
                        xerr=sx,
                        yerr=sy,
                        color=c,
                        marker=marker,
                        lw=lw,
                        ms=ms,
                        elinewidth=elw,
                        label=label)


if __name__ == '__main__':

    from datavyz import ge

    fig, ax = ge.scatter(Y=np.random.randn(4, 10),
                         sY=np.random.randn(4, 10),
                         xlabel='xlabel (xunit)',
                         ylabel='ylabel (yunit)',
                         title='datavyz demo plot')
    ge.savefig(fig, 'docs/scatter.png')

    # two_variable_analysis(np.random.randn(10), np.random.randn(10),
    #                       colormap=viridis)
Exemple #6
0
                  label='mean', color=graph.purple)
    # # max of power over intervals
    AX[1][1].plot(np.abs(coefs).max(axis=1), freqs,\
                  label='max.', color=graph.red)
    graph.set_plot(AX[1][1], xlabel=envelope_label)
    graph.legend(AX[1][1], loc=(0.1, 1.))

    return fig, AX


if __name__ == '__main__':

    from datavyz import ge
    from analyz.freq_analysis.wavelet_transform import my_cwt  # continuous wavelet transform

    dt, tstop = 1e-4, 1.
    t = np.arange(int(tstop / dt)) * dt

    freq1, width1, freq2, width2, freq3, width3 = 10., 100e-3, 40., 40e-3, 70., 20e-3
    data = 3.2+np.cos(2*np.pi*freq1*t)*np.exp(-(t-.5)**2/2./width1**2)+\
        np.cos(2*np.pi*freq2*t)*np.exp(-(t-.2)**2/2./width2**2)+\
        np.cos(2*np.pi*freq3*t)*np.exp(-(t-.8)**2/2./width3**2)

    # Continuous Wavelet Transform analysis
    freqs = np.linspace(1, 90, 40)
    coefs = my_cwt(data, freqs, dt)

    fig, AX = ge.time_freq_plot(t, freqs, data, coefs)

    ge.savefig(fig, 'docs/time-freq.png')
Exemple #7
0
    LIMS = [[np.inf, -np.inf] for f in features]
    for i, key_i in enumerate(features):
        hist(graph, data[key_i], ax=np.ravel(AX)[i],
             ylabel='', xlabel=key_i, axes_args={'spines':'bottom'})

    for i in range(len(features), len(np.ravel(AX))):
        np.ravel(AX)[i].axis('off')
        
    return fig, AX

if __name__=='__main__':

    
    from datavyz import ge
    
    # breast cancer dataset from datavyz.klearn
    from sklearn.datasets import load_breast_cancer
    raw = load_breast_cancer()
    
    data = {}
    for feature, values in zip(raw['feature_names'], raw['data']):
        data[feature+'\n(log)'] = np.log(values)
        
    fig, AX = ge.features_plot(data, ms=3)

    ge.savefig(fig, 'docs/features-plot.png')
    ge.show()


Exemple #8
0
    # ax.set_xlim(xlim)


if __name__ == '__main__':

    x = 32.23545345e-5
    print(sci_str(x, rounding=2))
    print(from_pval_to_star(x))
    for i in range(20):
        print(int_to_roman(i))

    from datavyz import ge

    fig, AX = ge.figure(axes=(10, 1), figsize=(.7, .7), bottom=1.5)
    for i, ax in enumerate(AX):
        ge.top_left_letter(ax, ge.int_to_roman(i + 1))
        ge.matrix(np.random.randn(10, 10), ax=ax)

    sax = ge.arrow(fig, [0.04, .2, .93, 0.])
    ge.annotate(fig, 'time', (.5, .17), ha='center')

    ge.savefig(fig, 'docs/annotations1.png')
    ge.show()

    # from datavyz..graphs import *
    # fig, ax = figure()
    # ax.plot(np.random.randn(30), np.random.randn(30), 'o')
    # bar_scales(ax, xbar=2, ybar=2, location='bottom left',
    #            ybar_label=r'10$\mu$V', xbar_label='200ms')
    # show()
Exemple #9
0
                alpha=alpha)
    elif orientation == 'horizontal':
        ax.bar(.5 * (be[1:] + be[:-1]),
               hist,
               width=be[1] - be[0],
               edgecolor=edgecolor,
               facecolor=facecolor,
               lw=lw,
               label=label,
               alpha=alpha)

    if 'xlabel' not in axes_args:
        axes_args['xlabel'] = xlabel
    if 'ylabel' not in axes_args:
        axes_args['ylabel'] = ylabel

    graph.set_plot(ax, **axes_args)
    if title != '':
        graph.title(ax, title)

    return fig, ax


if __name__ == '__main__':

    from datavyz import ge

    fig, ax = ge.hist(np.random.randn(100), xlabel='some value')

    ge.savefig(fig, 'docs/hist-plot.png')
Exemple #10
0
import numpy as np

from datavyz import ge

fig, ax = ge.plot(Y=np.random.randn(4, 10),
                  sY=np.random.randn(4, 10),
                  xlabel='xlabel (xunit)',
                  ylabel='ylabel (yunit)',
                  title='datavyz demo plot')
ge.savefig(fig, 'docs/demo.png')
ge.show()
Exemple #11
0
#     width = box.width
#     height = box.height
#     inax_position  = ax.transAxes.transform(rect[0:2])
#     transFigure = fig.transFigure.inverted()
#     infig_position = transFigure.transform(inax_position)
#     x = infig_position[0]
#     y = infig_position[1]
#     width *= rect[2]
#     height *= rect[3]  # <= Typo was here
#     subax = fig.add_axes([x,y,width,height],facecolor=facecolor)
#     # x_labelsize = subax.get_xticklabels()[0].get_size()
#     # y_labelsize = subax.get_yticklabels()[0].get_size()
#     # x_labelsize *= rect[2]**0.5
#     # y_labelsize *= rect[3]**0.5
#     # subax.xaxis.set_tick_params(labelsize=x_labelsize)
#     # subax.yaxis.set_tick_params(labelsize=y_labelsize)
#     return subax

if __name__ == '__main__':

    from datavyz import ge

    y = np.exp(np.random.randn(100))
    fig, ax = ge.plot(y, xlabel='time', ylabel='y-value')
    sax = ge.inset(ax, [.5, .8, .5, .4])
    sax2 = ge.inset(fig, [0.1, 0.1, .3, .2])
    ge.hist(y, bins=10, ax=sax, axes_args={'spines': []}, xlabel='y-value')
    ge.hist(y, bins=10, ax=sax2, axes_args={'spines': []}, xlabel='y-value')
    ge.savefig(fig, 'docs/inset.png')
    ge.show()