Beispiel #1
0
    # Save the plot
    f.tight_layout()
    png_template = os.path.dirname(__file__) + "/%s.png"
    f.savefig(png_template % "example_plot")

    # Carousel images
    plots = [
        "lmplot", "tsplot", "violinplot", "interactplot", "corrplot",
        "distplot"
    ]
    styles = {p: "darkgrid" for p in plots}
    styles["violinplot"] = "whitegrid"
    styles["distplot"] = "nogrid"

    figsize = (6, 4.2)
    for plot in plots:
        sns.set_axes_style(styles[plot], "notebook")

        if plot == "distplot":
            f, (ax1, ax2) = plt.subplots(2, 1, sharey=True, figsize=figsize)
            distplot_hist(ax1)
            distplot_kde(ax2)
        else:
            plot_func = locals()[plot]
            f, ax = plt.subplots(figsize=figsize)
            plot_func(ax)

        f.tight_layout()
        f.savefig(png_template % plot)
import pandas
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
import seaborn as sns
from scipy import stats

sns.set_color_palette("deep", desat=.6)
sns.set_axes_style("whitegrid", "talk")

import heroespy
from heroespy.util import times

file = "/Users/schriste/Dropbox/Developer/HEROES/HEROES-Telescope/SAS1_pointing_data.csv"

data = pandas.read_csv(file, parse_dates=True, index_col = 0)

ind = data['ctl el'].index
time_index=ind.indexer_between_time(times.solarobs_target2[0], times.solarobs_target2[1])
sas1_obs = data.iloc[time_index]

# in arcseconds
ctl_el = sas1_obs['ctl el'] * 60 * 60

plt.figure()
ax = ctl_el.plot()
ax.set_title('HEROES/SAS PYAS-F')
ax.set_xlabel('2013-09-21 [UTC]')
ax.set_ylabel('Elevation Offset [arcsec]')
ax.set_ybound(-100,100)
plt.savefig('PYASF_el_timeseries.pdf')
Beispiel #3
0
import collections
import seaborn as sns
import math
import warnings
import FGE_MISC.code.config as cfg
import mypymvpa.utilities.stats as mus
import plotly.plotly as plotly
import os

# #general

try:
    sns.set_style('white')
    sns.set_context('notebook')
except:
    sns.set_axes_style("white", "notebook")


def savefigure(f, fname, figdir, figsave='local', plotlyprivate=False):
    if figsave == 'local':
        f.savefig(os.path.join(figdir, fname + '.png'), bbox_inches='tight', dpi=400)
    elif figsave == 'plotly':
        plotly.sign_in('askerry', 'tn0zp19ph1')
        plotly.plot_mpl(f, filename=fname, auto_open=False, world_readable=plotlyprivate)


def nonnancorr(array1, array2):
    if np.isnan(np.sum(array1)) or np.isnan(np.sum(array2)):
        array1, array2 = np.array(array1), np.array(array2)
        arrays = np.array(zip(array1, array2))
        nonnans = np.where(~np.isnan(arrays))[0]
Beispiel #4
0
def simplebar(values, width=.9, bars=True, elinewidth=2, markersize=None, fmt=None, xtickrotation=None, figsize=[4, 4],
              yerr=None, xlabel=None, xlim=None, xticklabels=None, ylabel=None, yticklabels=None, title=None, ylim=None,
              colors=['b'], chanceline=None, despine=False, show=True):
    '''takes various optional parameters and makes simple bar chart. at minumim requires set of values to plot, nothing else.
    example of more complex (and strange) usage: simplebar(values, yerr=[.2, .4, .5, .3, .6, .1], xlabel="x", ylabel="y", yticklabels=['1','2','6','7', 'g', 'h',  'j', 'v', '4'], xticklabels=['a','b','c','d','e','f'], chanceline={'chance':3, 'linetype':'solid', 'linecolor':'r'}, ylim=[-3,10])'''
    #deal with some sns version issues
    try:
        sns.set_style('white')
        sns.set_context('notebook')
    except:
        sns.set_axes_style("white", "notebook")
    f, ax = plt.subplots(figsize=figsize)
    if bars:
        ax.bar(range(len(values)), values, color=colors, width=width)
    if any(yerr):
        if len(colors) > 1:
            while len(colors) < len(values):
                colors.extend(colors)
            for vn, v in enumerate(values):
                baseval = [0 for el in values]
                basesem = [0 for el in values]
                baseval[vn] = v
                basesem[vn] = yerr[vn]
                ax.errorbar(np.arange(len(baseval)) + width / 2, baseval, yerr=basesem, color=colors[vn],
                            ecolor=colors[vn], linestyle='None', fmt=fmt, elinewidth=elinewidth, markersize=markersize)
        else:
            ax.errorbar(np.arange(len(values)) + width / 2, values, yerr=yerr, color=colors, linestyle='None', fmt=fmt,
                        elinewidth=elinewidth, markersize=markersize)
    if xlabel:
        ax.set_xlabel(xlabel)
    if ylabel:
        ax.set_ylabel(ylabel)
    if title:
        ax.set_title(title)
    if xticklabels:
        if xtickrotation != None:
            rotation = xtickrotation
        else:
            if len(xticklabels[0]) > 3:
                rotation = 90
            else:
                rotation = 0
        ax.set_xticks(np.arange(len(xticklabels)) + width / 2)
        ax.set_xticklabels(xticklabels, rotation=rotation)
    else:
        ax.set_xticklabels([])
    if yticklabels:
        ax.set_yticklabels(yticklabels)
    if ylim:
        ax.set_ylim(ylim)
    if not xlim:
        xlim = [-width / 8, len(values)]
    ax.set_xlim(xlim)
    if chanceline:
        chance = chanceline['chance']
        try:
            linetype = chanceline['linetype']
        except:
            linetype = 'dashed'
        try:
            linecolor = chanceline['linecolor']
        except:
            linecolor = 'orange'
        ax.plot(xlim, [chance for el in xlim], ls=linetype, color=linecolor)
    if despine:
        sns.despine(fig=f, ax=ax, top=True, right=True, left=False, bottom=False, trim=False)
    if show:
        plt.show()
    try:
        return f, ax
    except: return ax
Beispiel #5
0
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

sns.set_axes_style('nogrid', 'talk', 'Helvetica')
import brewer2mpl
from itertools import cycle

from sklearn.decomposition import PCA
from scipy.spatial.distance import pdist, squareform
from sklearn.cluster import AffinityPropagation, KMeans, DBSCAN, \
    spectral_clustering


class Data(object):
    def __init__(self, psi, n_components, step=0.1):
        self.psi = psi
        self.psi_fillna_mean = self.psi.T.fillna(self.psi.mean(axis=1)).T
        self.step = step
        self.n_components = n_components
        self.binify()
        self.reduce()

    def binify(self):
        self.bins = np.arange(0, 1 + self.step, self.step)
        ncol = int(1 / self.step)
        nrow = self.psi.shape[0]
        self.binned = np.zeros((nrow, ncol))
        for i, (name, row) in enumerate(self.psi.iterrows()):
            self.binned[i, :] = np.histogram(row, bins=self.bins,
                                             normed=True)[0]
Beispiel #6
0
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

sns.set_axes_style('nogrid', 'talk', 'Helvetica')
import brewer2mpl
from itertools import cycle

from sklearn.decomposition import PCA
from scipy.spatial.distance import pdist, squareform
from sklearn.cluster import AffinityPropagation, KMeans, DBSCAN, \
    spectral_clustering


class Data(object):
    def __init__(self, psi, n_components, step=0.1):
        self.psi = psi
        self.psi_fillna_mean = self.psi.T.fillna(self.psi.mean(axis=1)).T
        self.step = step
        self.n_components = n_components
        self.binify()
        self.reduce()

    def binify(self):
        self.bins = np.arange(0, 1 + self.step, self.step)
        ncol = int(1 / self.step)
        nrow = self.psi.shape[0]
        self.binned = np.zeros((nrow, ncol))
        for i, (name, row) in enumerate(self.psi.iterrows()):
            self.binned[i, :] = np.histogram(row, bins=self.bins, normed=True)[
                0]
import pandas
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
import seaborn as sns
from scipy import stats

sns.set_color_palette("deep", desat=.6)
sns.set_axes_style("whitegrid", "talk")

import heroespy
from heroespy.util import times

file = "/Users/schriste/Dropbox/Developer/HEROES/HEROES-Telescope/SAS1_pointing_data.csv"

data = pandas.read_csv(file, parse_dates=True, index_col=0)

ind = data['ctl el'].index
time_index = ind.indexer_between_time(times.solarobs_target2[0],
                                      times.solarobs_target2[1])
sas1_obs = data.iloc[time_index]

# in arcseconds
ctl_el = sas1_obs['ctl el'] * 60 * 60

plt.figure()
ax = ctl_el.plot()
ax.set_title('HEROES/SAS PYAS-F')
ax.set_xlabel('2013-09-21 [UTC]')
ax.set_ylabel('Elevation Offset [arcsec]')
ax.set_ybound(-100, 100)
Beispiel #8
0
    ax = plt.subplot(gs[5, 1], sharey=ax)
    distplot_kde(ax)

    # Save the plot
    f.tight_layout()
    png_template = os.path.dirname(__file__) + "/%s.png"
    f.savefig(png_template % "example_plot")

    # Carousel images
    plots = ["lmplot", "tsplot", "violinplot", "interactplot",
             "corrplot", "distplot"]
    styles = {p: "darkgrid" for p in plots}
    styles["violinplot"] = "whitegrid"
    styles["distplot"] = "nogrid"

    figsize = (6, 4.2)
    for plot in plots:
        sns.set_axes_style(styles[plot], "notebook")

        if plot == "distplot":
            f, (ax1, ax2) = plt.subplots(2, 1, sharey=True, figsize=figsize)
            distplot_hist(ax1)
            distplot_kde(ax2)
        else:
            plot_func = locals()[plot]
            f, ax = plt.subplots(figsize=figsize)
            plot_func(ax)

        f.tight_layout()
        f.savefig(png_template % plot)
     for dataset in alldata:
         if dataset.roi==roi and dataset.disc==disc and dataset.selector==sel:
             string=roi+', '+disc+','+sel
             #print string
             values=np.array(dataset.accuracies)
             mean=np.nanmean(values)
             #print mean
             SEM=np.nanstd(values)/np.sqrt(len(values))
             #print SEM
             allplotsmean.append(mean)
             allplotssem.append(SEM)
             axislabels.append(labeldict[disc])
 base=np.array([0 for el in allplotsmean])
 colors=['g','b','r']
 colors=sns.color_palette(['#3E7C10','#6666C2', '#884433'])
 sns.set_axes_style('nogrid', 'notebook')
 sns.despine()
 fig, axis = plt.subplots(1, figsize=[2.6,4]) 
 for valn,val in enumerate(allplotsmean):
     means=[el for el in base]
     means[valn]=val
     sems=[el for el in base]
     sems[valn]=allplotssem[valn]
     color=colors[valn]
     axis.errorbar(np.arange(len(means)), np.array(means), yerr=np.array(sems),elinewidth=3, markersize=12, fmt='o', color=color) 
     #axis.errorbar(np.arange(len(means[0:2])), np.array(means[0:2]), yerr=np.array(sems[0:2]),elinewidth=3, markersize=12, fmt='o', color=color) 
 axis.locator_params(nbins=len(allplotsmean)+2)
 #axis.locator_params(nbins=2,axis='x')
 #axis.set_xticklabels(axislabels[0:2], visible=0)
 axis.set_xticklabels(axislabels, visible=1)
 xlim_deets=[-.25, len(allplotsmean)-.75]