def test_summary_max_central_1(self):
     c = ChainConsumer()
     c.add_chain(self.data)
     c.configure(statistics="max_central")
     summary = c.analysis.get_summary()['0']
     expected = [3.5, 5, 6.5]
     assert np.all(np.isclose(summary, expected, atol=0.1))
def plot_clusters(clusters, weightsDF, centroids, labels, saveDir):
    weightNames = weightsDF.columns.tolist()
    centroidsDF = pd.DataFrame(data=centroids, columns=weightNames)
    numClusters = len(clusters.keys())

    # fig, ax = plt.subplots(nrows=6, ncols=6, sharex='col', sharey='row')
    # fig.subplots_adjust(wspace=0, hspace=0)
    # colmap = {1: 'r', 2: 'g', 3: 'b', 4: 'c', 5: 'm', 6: 'y'}
    # colors = list(map(lambda x: colmap[x + 1], labels))
    #
    # for i, label1 in enumerate(weightNames):
    #     for j, label2 in enumerate(weightNames):
    #         if label1 != label2 and i >= j:
    #             ax[i, j].scatter(weightsDF[label1], weightsDF[label2], color=colors, alpha=0.3)
    #             for idx, centroid in centroidsDF.iterrows():
    #                 pass  #ax[i, j].scatter(centroid[label1], centroid[label2], color=colmap[idx+1], s=20)
    #             if i == 5:
    #                 ax[i, j].set_xlabel(label2)
    #             if j == 0:
    #                 ax[i, j].set_ylabel(label1)
    # fig.savefig("{0}/clusters_distribution_k{1}.png".format(saveDir, numClusters))

    c = ChainConsumer()
    for clusterName in clusters.keys():
        c.add_chain(np.array(clusters[clusterName]['weights']),
                    parameters=weightNames,
                    name='c{0}'.format(clusterName))
    c.configure(smooth=None)
    try:
        c.plotter.plot(filename="{0}/clusters_contours_k{1}.png".format(
            saveDir, numClusters))
    except ValueError:
        c.plotter.plot()
Beispiel #3
0
def plot_all_files(df_all):
    output_file = "all_biascor_results.png"
    logging.info(f"Plotting all fits to {output_file}")

    c = ChainConsumer()
    labels = [r"$\Omega_m$", "$w$", r"$\sigma_{int}$"]
    data = []
    for name, df in df_all.groupby("name"):
        means = [df["omm"].mean(), df["w"].mean(), df["sigint"].mean()]
        if df.shape[0] < 2:
            name2 = name + " (showing mean error)"
            cov = np.diag(
                [df["omm_sig"].mean()**2, df["w_sig"].mean()**2, 0.01**2])
        else:
            name2 = name + " (showing scatter error)"
            cov = np.diag(
                [df["omm"].std()**2, df["w"].std()**2, df["sigint"].std()**2])
        c.add_covariance(means,
                         cov,
                         parameters=labels,
                         name=name2.replace("_", "\\_"))
        data.append([name, df["w"].mean(), df["w"].std(), df["w_sig"].mean()])
    wdf = pd.DataFrame(
        data, columns=["name", "mean_w", "scatter_mean_w", "mean_std_w"])
    wdf.to_csv(output_file.replace(".png", ".csv"),
               index=False,
               float_format="%0.4f")
    c.configure(statistics="mean")
    c.plotter.plot_summary(errorbar=True, filename=output_file)
 def test_output_text(self):
     consumer = ChainConsumer()
     consumer.add_chain(self.data, parameters=["a"])
     consumer.configure(bins=0.8)
     vals = consumer.analysis.get_summary()["a"]
     text = consumer.analysis.get_parameter_text(*vals)
     assert text == r"5.0\pm 1.5"
Beispiel #5
0
def debug_plots(std):
    print(std)

    res = load_stan_from_folder(std, merge=True, cut=False)
    chain, posterior, t, p, f, l, w, ow = res
    # print(w.mean())
    # import matplotlib.pyplot as plt
    # plt.hist(np.log(w), 100)
    # plt.show()
    # exit()
    logw = np.log(w)
    m = np.mean(logw)
    s = np.std(logw)
    print(m, s)
    logw -= (m + 3 * s)
    good = logw < 0
    logw *= good
    w = np.exp(logw)

    c = ChainConsumer()
    c.add_chain(chain, weights=w, name="corrected")
    c.configure(summary=True)
    c.plot(figsize=2.0, filename="output.png", parameters=9)

    c = ChainConsumer()
    c.add_chain(chain, name="uncorrected")
    c.add_chain(chain, weights=w, name="corrected")
    # c.add_chain(chain, name="calib")
    c.plot(filename="output_comparison.png", parameters=9, figsize=1.3)
    c.plot_walks(chains=1, filename="walks.png")
Beispiel #6
0
def threechain_multi_plot(start, filename, out, chainnames, paranames,
                          plotrange):
    fid = np.array([-1.0, 0.0])

    d1read = np.genfromtxt(filename[0])
    d2read = np.genfromtxt(filename[1])
    d3read = np.genfromtxt(filename[2])

    d1 = d1read[1000000:, (3, 4)] - fid
    d2 = d2read[1000000:, (3, 4)] - fid
    d3 = d3read[1000000:, (3, 4)] - fid

    c = ChainConsumer()
    c.add_chain(d1, parameters=paranames, name=chainnames[0])
    c.add_chain(d2, name=chainnames[1])
    c.add_chain(d3, name=chainnames[2])

    #c.configure(kde=[2,2],colors=['c','y'], sigmas=[1,2],shade=True,shade_alpha=0.2,shade_gradient=0.0)
    c.configure(colors=['b', 'g', 'r'],
                sigmas=[1],
                shade=True,
                shade_alpha=0.2,
                shade_gradient=0.0)
    fig = c.plotter.plot(figsize=2.0,
                         extents=plotrange,
                         filename="plots/" + out,
                         truth=[0.0, 0.0])
 def test_summary_area_default(self):
     c = ChainConsumer()
     c.add_chain(self.data)
     c.configure(summary_area=0.6827)
     summary = c.analysis.get_summary()['0']
     expected = [3.5, 5, 6.5]
     assert np.all(np.isclose(summary, expected, atol=0.1))
Beispiel #8
0
 def test_plotter_extents1(self):
     c = ChainConsumer()
     c.add_chain(self.data, parameters=["x"])
     c.configure()
     minv, maxv = c.plotter._get_parameter_extents("x", c.chains)
     assert np.isclose(minv, (5.0 - 1.5 * 3.7), atol=0.2)
     assert np.isclose(maxv, (5.0 + 1.5 * 3.7), atol=0.2)
 def test_summary_area_95(self):
     c = ChainConsumer()
     c.add_chain(self.data)
     c.configure(summary_area=0.95)
     summary = c.analysis.get_summary()['0']
     expected = [2, 5, 8]
     assert np.all(np.isclose(summary, expected, atol=0.1))
Beispiel #10
0
def contour_plot(fisher,
                 fiducials,
                 fname,
                 name='',
                 add_marker=False,
                 latex=True):
    from chainconsumer import ChainConsumer
    mean = [fiducials[key] for key in fisher.params]
    cov = np.linalg.inv(fisher.values)
    parameters = [latex_mapping[x]
                  for x in fisher.params] if latex else fisher.params

    c = ChainConsumer()
    c.add_covariance(mean, cov, parameters=parameters, name=name, shade=False)
    if add_marker:
        c.add_marker(mean,
                     parameters=parameters,
                     marker_style="*",
                     marker_size=100,
                     color="r",
                     name='')
    c.configure(usetex=False, serif=False, sigma2d=True, sigmas=[1])
    fig = c.plotter.plot()
    fig.set_size_inches(3 + fig.get_size_inches())
    fig.savefig(fname)
Beispiel #11
0
 def _make_corner_plot(self):
     """ Corner plot for a posterior distribution from the result """
     if self.opts.corner == 1:
         for jj in self.unique:
             model_mask = np.round(self.chain_burn[:, self.ind_model]) == jj
             chain_plot = self.chain_burn[model_mask, :]
             chain_plot = chain_plot[:, self.par_mask]
             figure = corner(chain_plot,
                             30,
                             labels=self.pars[self.par_mask])
             plt.savefig(self.outdir_all + '/' + self.psr_dir + '_corner_' + \
                         str(jj) + '_' + self.par_out_label + '.png')
             plt.close()
     elif self.opts.corner == 2:
         cobj = ChainConsumer()
         pars = self.pars.astype(str)
         pars = np.array(['$' + pp + '$' for pp in pars], dtype=str)
         for jj in self.unique:
             model_mask = np.round(self.chain_burn[:, self.ind_model]) == jj
             chain_plot = self.chain_burn[model_mask, :]
             chain_plot = chain_plot[:, self.par_mask]
             cobj.add_chain(chain_plot,
                            name=str(jj),
                            parameters=pars[self.par_mask].tolist())
         cobj.configure(serif=True,
                        label_font_size=12,
                        tick_font_size=12,
                        legend_color_text=False,
                        legend_artists=True)
         corner_name = self.outdir_all + '/' + self.psr_dir + '_' + \
                       self.par_out_label + '_corner.png'
         fig = cobj.plotter.plot(filename=corner_name)
         plt.close()
def plot_weights(spectra, removeNames, saveDir):
    """ Plot the weights parameter space """
    weightsDF, namesDF = get_weights(spectra, removeNames, lineType='All')
    weightsDFBals, namesDFBals = get_weights(spectra,
                                             removeNames,
                                             lineType='BALs')
    weightsDFNonBals, namesDFNonBals = get_weights(spectra,
                                                   removeNames,
                                                   lineType='nonBALs')
    # corner.corner(weightsDF)

    c = ChainConsumer()
    c.add_chain(weightsDFBals.values,
                parameters=weightsDF.columns.tolist(),
                name='BALs')
    c.add_chain(weightsDFNonBals.values,
                parameters=weightsDF.columns.tolist(),
                name='non-BALs')
    # c.add_chain(weightsDF.values, parameters=weightsDF.columns.tolist(), name='All')
    c.configure(smooth=None)

    try:
        c.plotter.plot(
            filename="{0}/weights_bal_vs_nonBal.png".format(saveDir))
    except ValueError:
        c.plotter.plot()
Beispiel #13
0
def DES_WFIRST_Planck_single_plot(filename, out, chainnames, paranames):
	d1 = np.genfromtxt(filename[0])
	d2 = np.genfromtxt(filename[1])
	d3 = np.genfromtxt(filename[2])
	d4 = np.genfromtxt(filename[3])

	d2[:,0]=d2[:,0]-0.0486
	d3[:,0]=d3[:,0]-0.0486
	d2[:,1]=d2[:,1]
	d3[:,1]=d3[:,1]
	
	Abbott = d1[:,(0,26)]
	DES = d2[:,(0,1)]
	WFIRST = d3[:,(0,1)]
	Planck = d4[:,(0,8)]
	
	Abbott[:,1]=Abbott[:,1]*(Abbott[:,0]/0.3)**0.5
	Abbott_weights=d1[:,28]

	Planck[:,1]=Planck[:,1]*(Planck[:,0]/0.3)**0.5
	Planck_weights=d4[:,10]

	DES[:,1]=((DES[:,1])*(DES[:,0]/0.3)**0.5)-0.0109
	WFIRST[:,1]=((WFIRST[:,1])*(WFIRST[:,0]/0.3)**0.5)-0.0109
	
	c = ChainConsumer()
	c.add_chain(Abbott[:,(0,1)],weights=Abbott_weights,parameters=paranames,name =chainnames[0])
	c.add_chain(Planck[:,(0,1)],weights=Planck_weights, name =chainnames[3])
	c.add_chain(DES[20000:,(0,1)], name =chainnames[1])
	c.add_chain(WFIRST[20000:,(0,1)], name =chainnames[2])
		
	c.configure(shade=True, kde=1.5, shade_alpha=0.2, colors=["g","o","r","b"], linewidths=1.2, bar_shade=True)
	#c.configure(shade=[True,False,False],shade_alpha=[0.2,0.2,0.2],linestyles=["--", "-", "-."],linewidths=[0.5,1.,1.])	
	fig = c.plotter.plot(extents=[[0.2, 0.48], [0.7, 0.98]],figsize=2.0,filename="/Users/timeifler/Dropbox/cosmolike_store/WFIRST_forecasts/plots/"+out)
Beispiel #14
0
 def plot_corner(self, nburn=10000):
     c = ChainConsumer()
     cols = 'per2 per3 ecosw2 ecosw3 esinw2 esinw3 inc2 inc3 masse2 masse3'.split(
     )
     chain = self.chain_without_burnin()
     c.add_chain(chain, parameters=cols)
     c.configure(sigmas=[0, 1, 2])
     c.plotter.plot()
Beispiel #15
0
 def plot_corner_interesting(self):
     c = ChainConsumer()
     cols = 'ecosw2 ecosw3 esinw2 esinw3 inc2 inc3 Omega3 masse2 masse3'.split(
     )
     chain = self.chain_without_burnin()
     c.add_chain(np.array(chain[cols]), parameters=cols)
     c.configure(sigmas=[0, 1, 2])
     c.plotter.plot()
Beispiel #16
0
def twochain_multi_plot_3x2pt_only(filename, out, chainnames, paranames,true):
	d1 = np.genfromtxt(filename[0])
	d2 = np.genfromtxt(filename[1])
	c = ChainConsumer()
	c.add_chain(d1[400000:,0:49], parameters=paranames, name =chainnames[0])
	c.add_chain(d2[400000:,0:49], name =chainnames[1])
	c.configure(shade=[True,False],shade_alpha=[0.2,0.2],linestyles=["--", "-"],linewidths=[0.5,1.])	
	fig = c.plotter.plot(truth=true,filename="/Users/timeifler/Dropbox/cosmolike_store/WFIRST_forecasts/plots/"+out)
 def test_shade_alpha_algorithm2(self):
     consumer = ChainConsumer()
     consumer.add_chain(self.data)
     consumer.add_chain(self.data)
     consumer.configure()
     alpha0 = consumer.chains[0].config["shade_alpha"]
     alpha1 = consumer.chains[0].config["shade_alpha"]
     assert alpha0 == 1.0 / 2.0
     assert alpha1 == 1.0 / 2.0
Beispiel #18
0
def twochain_single_plot(filename, out, chainnames, paranames,true):
	d1 = np.genfromtxt(filename[0])
	d2 = np.genfromtxt(filename[1])
	c = ChainConsumer()
	c.add_chain(d1[200000:,(0,1)], parameters=paranames, name =chainnames[0])
	c.add_chain(d2[200000:,(0,1)], name =chainnames[1])
	c.configure(shade=True,kde=2.0,shade_alpha=0.2, bar_shade=True)
	#c.configure(shade=[True,False,False],shade_alpha=[0.2,0.2,0.2],linestyles=["--", "-", "-."],linewidths=[0.5,1.,1.])	
	fig = c.plotter.plot(truth=true,figsize=2.0,filename="/Users/timeifler/Dropbox/cosmolike_store/WFIRST_forecasts/plots/"+out)
Beispiel #19
0
def plot_contours(chains, params_names, params_fid, figname,
    keep=None, extents = None, chain_names=None, plot_hists=True,
    blind= None, shade_alpha = None, figsize=(7,7), summary=None,
    shade = None, colors = None, linestyles = None, linewidths=None,
    kde = None, legend_location=None, flip=False, sigmas=[0,1,2], multinest=None ):
    """
    keep : list. choose in the second chain
    params_fid : fiducial value of chain2

    """

    if chain_names is None : chain_names = ['chain'+str(i) for i in len(chains)]

    if keep is None :
        pn = params_names[0]
        pf = params_fid
    else :
        pn = [params_names[0][i] for i in keep]
        pf = [params_fid[i] for i in keep]
        #extents = [extents[i] for i in keep]

    if blind: pf = None

    c = ChainConsumer()

    if multinest is None :
        multinest = [ False for i in range(len(chains)) ]
    for i in range(len(chains)):
        if multinest[i]:
            weights = chains[i][:,-1]
            chain_i = chains[i][:,:-1]
        else :
            weights = None
            chain_i = chains[i]

        c.add_chain(chain_i, parameters = params_names[i], name=chain_names[i],weights=weights)
        #print c.analysis.get_covariance(chain=i)[1]
    statistics = ['max' for i in range(len(chains))]  #["max","max","max","max","max", "max"]
    if kde is None :kde=[ False for i in range(len(chains))] #False,False,False,False,False,False][:len(chains)]
    c.configure(statistics=statistics,#[:len(chains)],
                linestyles=linestyles,#[:len(chains)],
                label_font_size=20, tick_font_size =20,
                summary=summary, #[: len(chains)],
                sigmas=sigmas,
                shade=shade, #[: len(chains)], \
                colors=colors, #[: len(chains)], \
                shade_alpha = shade_alpha, #[: len(chains)],
                linewidths=linewidths, #[:len(chains)],
                kde = kde,
                plot_hists=plot_hists,
                flip=flip,
                legend_location=legend_location,
                legend_kwargs = {'loc':'best'})

    fig = c.plotter.plot(filename=figname, figsize=figsize, truth = pf, parameters =pn, extents=extents, blind=blind)
    print "plot save to ", figname
    return c, fig
 def test_shade_alpha_algorithm2(self):
     consumer = ChainConsumer()
     consumer.add_chain(self.data)
     consumer.add_chain(self.data)
     consumer.configure()
     alpha0 = consumer.chains[0].config["shade_alpha"]
     alpha1 = consumer.chains[0].config["shade_alpha"]
     assert alpha0 == 1.0 / np.sqrt(2.0)
     assert alpha1 == 1.0 / np.sqrt(2.0)
 def test_summary_no_smooth(self):
     tolerance = 5e-2
     consumer = ChainConsumer()
     consumer.add_chain(self.data)
     consumer.configure(smooth=0, bins=2.4)
     summary = consumer.analysis.get_summary()
     actual = np.array(list(summary.values())[0])
     expected = np.array([3.5, 5.0, 6.5])
     diff = np.abs(expected - actual)
     assert np.all(diff < tolerance)
 def test_summary(self):
     tolerance = 4e-2
     consumer = ChainConsumer()
     consumer.add_chain(self.data[::10])
     consumer.configure(kde=True)
     summary = consumer.analysis.get_summary()
     actual = np.array(list(summary.values())[0])
     expected = np.array([3.5, 5.0, 6.5])
     diff = np.abs(expected - actual)
     assert np.all(diff < tolerance)
 def test_stats_cum_skew(self):
     tolerance = 3e-2
     consumer = ChainConsumer()
     consumer.add_chain(self.data_skew)
     consumer.configure(statistics="cumulative")
     summary = consumer.analysis.get_summary()
     actual = np.array(list(summary.values())[0])
     expected = np.array([1.27, 2.01, 3.11])
     diff = np.abs(expected - actual)
     assert np.all(diff < tolerance)
 def test_summary_specific(self):
     tolerance = 5e-2
     consumer = ChainConsumer()
     consumer.add_chain(self.data, name="A")
     consumer.configure(bins=0.8)
     summary = consumer.analysis.get_summary(chains="A")
     actual = np.array(list(summary.values())[0])
     expected = np.array([3.5, 5.0, 6.5])
     diff = np.abs(expected - actual)
     assert np.all(diff < tolerance)
 def test_stats_cum_normal(self):
     tolerance = 5e-2
     consumer = ChainConsumer()
     consumer.add_chain(self.data)
     consumer.configure(statistics="cumulative")
     summary = consumer.analysis.get_summary()
     actual = np.array(list(summary.values())[0])
     expected = np.array([3.5, 5.0, 6.5])
     diff = np.abs(expected - actual)
     assert np.all(diff < tolerance)
Beispiel #26
0
def run_mcmc(img_xobs, img_yobs, fig_dir, d, lenses, pars, cov, nwalkers=100, nsteps=200, burn=20, fits_file=None, img_name=''):
    names = img_xobs.keys()

    # Define likelihood function
    @pymc.observed
    def logL(value=0., tmp=pars):
        """ Calculate log-likelihood probability.
        Minimise the variance in the source position from all images. """
        for lens in lenses:
            lens.setPars()

        x_src, y_src = {}, {}
        lnlike_dict = {}

        for name in names:
            x_src[name], y_src[name] = pylens.getDeflections(lenses, [img_xobs[name], img_yobs[name]], d[name])
            lnlike_dict[name] = -0.5 * (x_src[name].var() + y_src[name].var())
        print(sum(lnlike_dict.values()), float(lenses[0].x), float(lenses[0].y), float(lenses[0].b), float(lenses[0].q), float(lenses[0].pa))
        return sum(lnlike_dict.values())

    # Run MCMC
    sampler = myEmcee.Emcee(pars+[logL], cov, nwalkers=nwalkers, nthreads=46)
    sampler.sample(nsteps)

    # Plot chains
    result = sampler.result()
    posterior, samples, _, best = result
    print("best", best)
    import pylab
    for j in range(nwalkers):
        pylab.plot(posterior[:, j])
    for i in range(len(pars)):
        pylab.figure()
        for j in range(nwalkers):
            pylab.plot(samples[:, j, i])

    # Trim initial samples (ie the burn-in) and concatenate chains
    samples = samples[burn:].reshape(((nsteps-burn) * nwalkers, len(pars)))

    # Plot parameter contours and mcmc chains
    param_names = ['$x_{lens}$', '$y_{lens}$', '$b_{lens}$', '$q_{lens}$', '$pa_{lens}$']
    if len(pars) == 7:
        param_names += ['$b_{shear}$', '$pa_{shear}$']
    c = ChainConsumer()
    c.add_chain(samples, parameters=param_names)
    c.configure(summary=True, cloud=True)
    fig = c.plotter.plot()
    fig.savefig(os.path.join(fig_dir, 'parameter_contours.png'), transparent=False)
    fig = c.plotter.plot_walks(convolve=100)
    fig.savefig(os.path.join(fig_dir, 'mcmc_walks.png'), transparent=False)

    if fits_file:
        fig = plt.figure(figsize=(13, 13))
        plot_image_and_contours(fits_file, samples, fig_dir, img_name, save=False, figname=fig)
        plot_source_and_pred_lens_positions(best, img_xobs, img_yobs, d, fig_dir, plotimage=False)
 def test_shade_alpha_algorithm3(self):
     consumer = ChainConsumer()
     consumer.add_chain(self.data)
     consumer.add_chain(self.data)
     consumer.add_chain(self.data)
     consumer.configure()
     alphas = [c.config["shade_alpha"] for c in consumer.chains]
     assert len(alphas) == 3
     assert alphas[0] == 1.0 / 3.0
     assert alphas[1] == 1.0 / 3.0
     assert alphas[2] == 1.0 / 3.0
 def test_shade_alpha_algorithm3(self):
     consumer = ChainConsumer()
     consumer.add_chain(self.data)
     consumer.add_chain(self.data)
     consumer.add_chain(self.data)
     consumer.configure()
     alphas = [c.config["shade_alpha"] for c in consumer.chains]
     assert len(alphas) == 3
     assert alphas[0] == 1.0 / np.sqrt(3.0)
     assert alphas[1] == 1.0 / np.sqrt(3.0)
     assert alphas[2] == 1.0 / np.sqrt(3.0)
Beispiel #29
0
 def test_plotter_extents5(self):
     x, y = np.linspace(-3, 3, 200), np.linspace(-5, 5, 200)
     xx, yy = np.meshgrid(x, y, indexing='ij')
     xs, ys = xx.flatten(), yy.flatten()
     chain = np.vstack((xs, ys)).T
     pdf = (1 / (2 * np.pi)) * np.exp(-0.5 * (xs * xs + ys * ys / 4))
     c = ChainConsumer()
     c.add_chain(chain, parameters=['x', 'y'], weights=pdf, grid=True)
     c.configure()
     minv, maxv = c.plotter._get_parameter_extents("x", c.chains)
     assert np.isclose(minv, -3, atol=0.001)
     assert np.isclose(maxv, 3, atol=0.001)
Beispiel #30
0
def make_real_corner(i):
    chain = pd.read_csv(chainout%i, dtype='float64', delim_whitespace=True)
    chain = chain.as_matrix()
    from chainconsumer import ChainConsumer
    labs=[r"$d_0'$",r"$d_1'$",r"$e_1'$",r"$f_0'$",r"$f_1'$",r"$g_0'$",r"$g_1'$"]
    c = ChainConsumer()
    c.add_chain(chain, parameters=labs)
    c.configure(kde=True, tick_font_size=10, label_font_size=24, max_ticks=3, sigmas=[0,1,2,3], usetex=True)#, statistics='max_symmetric')
    fig = c.plotter.plot()#legend=True)
    plt.subplots_adjust(hspace=0, wspace=0)
    plt.savefig("fig_Rcorner.pdf", bbox_inches='tight')
    plt.show()    
 def test_remove_chain_by_name(self):
     tolerance = 5e-2
     consumer = ChainConsumer()
     consumer.add_chain(self.data * 2, name="a")
     consumer.add_chain(self.data, name="b")
     consumer.remove_chain(chain="a")
     consumer.configure()
     summary = consumer.analysis.get_summary()
     assert isinstance(summary, dict)
     actual = np.array(list(summary.values())[0])
     expected = np.array([3.5, 5.0, 6.5])
     diff = np.abs(expected - actual)
     assert np.all(diff < tolerance)
Beispiel #32
0
 def plot_corner_ecosw(self):
     c = ChainConsumer()
     chain = self.chain_without_burnin()
     cols = 'ecosw2 ecosw3'.split()
     parameters = [key2tex(k) for k in cols]
     c.add_chain(np.array(chain[cols]), parameters=parameters)
     c.configure(plot_hists=False)
     c.plotter.plot(figsize=(3, 3))
     fig = gcf()
     axL = fig.get_axes()
     setp(axL, xlim=(-0.301, 0.3))
     setp(axL, ylim=(-0.301, 0.3))
     fig.set_tight_layout(True)
 def test_remove_chain_by_name(self):
     tolerance = 5e-2
     consumer = ChainConsumer()
     consumer.add_chain(self.data * 2, name="a")
     consumer.add_chain(self.data, name="b")
     consumer.remove_chain(chain="a")
     consumer.configure()
     summary = consumer.analysis.get_summary()
     assert isinstance(summary, dict)
     actual = np.array(list(summary.values())[0])
     expected = np.array([3.5, 5.0, 6.5])
     diff = np.abs(expected - actual)
     assert np.all(diff < tolerance)
 def test_summary_disjoint(self):
     tolerance = 5e-2
     consumer = ChainConsumer()
     consumer.add_chain(self.data, parameters="A")
     consumer.add_chain(self.data, parameters="B")
     consumer.configure(bins=0.8)
     summary = consumer.analysis.get_summary(parameters="A")
     assert len(summary) == 2  # Two chains
     assert summary[1] == {}  # Second chain doesnt have param A
     actual = summary[0]["A"]
     expected = np.array([3.5, 5.0, 6.5])
     diff = np.abs(expected - actual)
     assert np.all(diff < tolerance)
 def test_remove_multiple_chains3(self):
     tolerance = 5e-2
     consumer = ChainConsumer()
     consumer.add_chain(self.data * 2, parameters=["p1"], name="a")
     consumer.add_chain(self.data, parameters=["p2"], name="b")
     consumer.add_chain(self.data * 3, parameters=["p3"], name="c")
     consumer.remove_chain(chain=["a", 2])
     consumer.configure()
     summary = consumer.analysis.get_summary()
     assert isinstance(summary, dict)
     assert "p2" in summary
     assert "p1" not in summary
     assert "p3" not in summary
     actual = np.array(list(summary.values())[0])
     expected = np.array([3.5, 5.0, 6.5])
     diff = np.abs(expected - actual)
     assert np.all(diff < tolerance)
"""
======================
Cloud and Sigma Levels
======================

Choose custom sigma levels and display point cloud.

In this example we display more sigma levels, turn on the point cloud, and
disable the parameter summaries on the top of the marginalised distributions.

Note that because of the very highly correlated distribution we have, it is
useful to increase the number of bins the plots are generated with, to capture the
thinness of the correlation.
"""

import numpy as np
from numpy.random import normal, multivariate_normal
from chainconsumer import ChainConsumer

np.random.seed(1)
cov = normal(size=(3, 3))
data = multivariate_normal(normal(size=3), np.dot(cov, cov.T), size=100000)

c = ChainConsumer().add_chain(data, parameters=["$x$", "$y$", "$z$"])
c.configure(summary=False, bins=1.4, cloud=True, sigmas=np.linspace(0, 2, 10))
fig = c.plotter.plot()

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
Beispiel #37
0
"""
===============
Subplot Spacing
===============

By default ChainConsumer will reduce subplot whitespace when you hit
a certain dimensionality, but you can also customise this yourself.
"""

import numpy as np
from numpy.random import normal, random, multivariate_normal
from chainconsumer import ChainConsumer


np.random.seed(0)
cov = random(size=(3, 3))
data = multivariate_normal(normal(size=3), np.dot(cov, cov.T), size=200000)

c = ChainConsumer().add_chain(data, parameters=["$x$", "$y$", "$z$"])
c.configure(spacing=0.0)
fig = c.plotter.plot(figsize="column")

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
Beispiel #38
0
np.random.seed(2)
cov = normal(size=(2, 2)) + np.identity(2)
d1 = multivariate_normal(normal(size=2), np.dot(cov, cov.T), size=100000)
cov = normal(size=(2, 2)) + np.identity(2)
d2 = multivariate_normal(normal(size=2), np.dot(cov, cov.T), size=100000)
cov = normal(size=(2, 2)) + np.identity(2)
d3 = multivariate_normal(normal(size=2), np.dot(cov, cov.T), size=1000000)

c = ChainConsumer()
c.add_chain(d1, parameters=["$x$", "$y$"])
c.add_chain(d2)
c.add_chain(d3)

c.configure(linestyles=["-", "--", "-"], linewidths=[1.0, 3.0, 1.0],
            bins=[3.0, 1.0, 1.0], colors=["#1E88E5", "#D32F2F", "#111111"],
            smooth=[0, 1, 2], shade=[True, True, False],
            shade_alpha=[0.2, 0.1, 0.0], bar_shade=[True, False, False])
fig = c.plotter.plot()

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.

###############################################################################
# List options are useful for when the properties of the chains are
# interconnected. But if you know the properties at the start,
# you can define them when adding the chains. List options will not
# override explicit chain configurations, so you can use the global
# configure to set options for all chains you haven't explicitly specified.
#
# Note here how even though we set 'all' chains to dotted lines of width 2, our third
# chain, with its explicit options, ignores that.
Normally when plotting more than two chains, shading is removed so
you can clearly see the outlines. However, you can turn shading back
on and modify the shade opacity if you prefer colourful plots.

Note that the contour shading and marginalised shading are separate
and are configured independently.

Colours should be given as hex colours.
"""

import numpy as np
from numpy.random import normal, multivariate_normal
from chainconsumer import ChainConsumer

np.random.seed(2)
cov = normal(size=(2, 2)) + np.identity(2)
d1 = multivariate_normal(normal(size=2), np.dot(cov, cov.T), size=100000)
cov = normal(size=(2, 2)) + np.identity(2)
d2 = multivariate_normal(normal(size=2), np.dot(cov, cov.T), size=100000)
cov = normal(size=(2, 2)) + np.identity(2)
d3 = multivariate_normal(normal(size=2), np.dot(cov, cov.T), size=100000)

c = ChainConsumer().add_chain(d1, parameters=["$x$", "$y$"]).add_chain(d2).add_chain(d3)
c.configure(colors=["#B32222", "#D1D10D", "#455A64"], shade=True, shade_alpha=0.2, bar_shade=True)
fig = c.plotter.plot()

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.


By default ChainConsumer uses the 2D levels, such that the contours will line up and agree with the
marginalised distributions shown above them, however you can also choose to switch to using the 1D
Gaussian method, such that the contour encloses 68% and 95% confidence regions, by switching `sigma2d` to `False` 

"""

import numpy as np
from numpy.random import multivariate_normal
from chainconsumer import ChainConsumer

np.random.seed(0)
data = multivariate_normal([0, 0], [[1, 0], [0, 1]], size=1000000)

c = ChainConsumer().add_chain(data, parameters=["$x$", "$y$"])
c.configure(flip=False, sigma2d=False, sigmas=[1, 2])  # The default case, so you don't need to specify sigma2d
fig = c.plotter.plot()

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.

###############################################################################
# Demonstrating the 1D Gaussian confidence levels. Notice the change in contour size
# The contours shown below now show the 68% and 95% confidence regions.

c = ChainConsumer().add_chain(data, parameters=["$x$", "$y$"])
c.configure(flip=False, sigma2d=True, sigmas=[1, 2])
fig = c.plotter.plot()


fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
    mean_scattered = multivariate_normal.rvs(mean=mean, cov=cov)
    data = multivariate_normal.rvs(mean=mean_scattered, cov=cov, size=5000)
    data2 = data + multivariate_normal.rvs(mean=[8, -8, 7], cov=cov)
    posterior = multivariate_normal.logpdf(data, mean=mean_scattered, cov=cov)
    plot_contour = i == 0

    c.add_chain(data, posterior=posterior, parameters=p, color='p', name="Sim1")

    c.add_chain(data2, posterior=posterior, parameters=p, color='k',
                marker_style="+", marker_size=20, name="Sim2", marker_alpha=0.5)

c.add_chain(data + np.array([4, -4, 3]), parameters=p, posterior=posterior, name="Contour Too",
            plot_contour=True, plot_point=True, marker_style="*", marker_size=40,
            color="a", shade=True, shade_alpha=0.3, kde=True, linestyle="--", bar_shade=True)

c.configure(legend_artists=True)

fig = c.plotter.plot()
fig.set_size_inches(2.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.

###############################################################################
# If you've loaded a whole host of chains in, but only want to focus on one
# set, you can also pick out all chains with the same name when plotting.

fig = c.plotter.plot(chains="Sim1")
fig.set_size_inches(2.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.

###############################################################################
# Finally, we should clarify what exactly the points mean! If you don't specify
# anything, by defaults the points represent the coordinates of the
# maximum posterior value. However, in high dimensional surfaces, this maximum
Multiple Colour Scatter!
========================

Why show only one colour, when you can display more!

In the basic colour example, we showed one parameter being used
to give colour information. However, you can pick a different colour, or no colour (`None`),
for each chain.

You can also pick the same parameter in multiple chains, and all the scatter points will be put
on the same colour scale. The underlying contours will still be distinguishable automatically
by adding alternative linestyles, as shown below.
"""

import numpy as np
from numpy.random import normal, multivariate_normal
from chainconsumer import ChainConsumer

np.random.seed(1)
cov = normal(size=(4, 4))
data = multivariate_normal(normal(size=4), np.dot(cov, cov.T), size=100000)
cov = 1 + 0.5 * normal(size=(4, 4))
data2 = multivariate_normal(4+normal(size=4), np.dot(cov, cov.T), size=100000)

c = ChainConsumer().add_chain(data, parameters=["$x$", "$y$", "$z$", "$g$"], name="a")
c.add_chain(data2, parameters=["$x$", "$y$", "$z$", "$t$"], name="b")
c.configure(color_params=["$g$", "$t$"])
fig = c.plotter.plot(figsize=1.75)

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
Beispiel #43
0
Lets try a few things to give what might be a usable plot to through into our latest paper.

Or something.

First lets mock some highly correlated data with colour scatter. And then throw a few more
data sets in to get some overlap.
"""

import numpy as np
from numpy.random import normal, multivariate_normal, uniform
from chainconsumer import ChainConsumer

np.random.seed(1)
n = 1000000
data = multivariate_normal([0.4, 1], [[0.01, -0.003], [-0.003, 0.001]], size=n)
data = np.hstack((data, (67 + 10 * data[:, 0] - data[:, 1] ** 2)[:, None]))
data2 = np.vstack((uniform(-0.1, 1.1, n), normal(1.2, 0.1, n))).T
data2[:, 1] -= (data2[:, 0] ** 2)
data3 = multivariate_normal([0.3, 0.7], [[0.02, 0.05], [0.05, 0.1]], size=n)

c = ChainConsumer()
c.add_chain(data2, parameters=["$\Omega_m$", "$-w$"], name="B")
c.add_chain(data3, name="S")
c.add_chain(data, parameters=["$\Omega_m$", "$-w$", "$H_0$"], name="P")

c.configure(color_params="$H_0$", shade=[True, True, False],
            shade_alpha=0.2, bar_shade=True, linestyles=["-", "--", "-"])
fig = c.plotter.plot(figsize=2.0, extents=[[0, 1], [0, 1.5]])

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
"""
===================
Changing Linestyles
===================

Customise the plot line styles.

In this example we customise the line styles used, and make use of
the ability to pass lists of parameters to the configuration methods.

"""

import numpy as np
from numpy.random import normal, multivariate_normal
from chainconsumer import ChainConsumer

np.random.seed(1)
cov = normal(size=(3, 3))
data = multivariate_normal(normal(size=3), np.dot(cov, cov.T), size=100000)
data2 = data * 1.1 + 0.5

c = ChainConsumer().add_chain(data, parameters=["$x$", "$y$", "$z$"]).add_chain(data2)
c.configure(linestyles=["-", "--"], linewidths=[1.0, 2.0],
            shade=[True, False], shade_alpha=[0.2, 0.0])
fig = c.plotter.plot()

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
colour mapped scatter plot.

We can *also* display this as a posterior surface by setting
`plot_colour_params=True`, if we wanted.
"""

import numpy as np
from numpy.random import normal, multivariate_normal
from chainconsumer import ChainConsumer

np.random.seed(1)
cov = normal(size=(3, 3))
data = multivariate_normal(normal(size=3), np.dot(cov, cov.T), size=100000)

c = ChainConsumer().add_chain(data, parameters=["$x$", "$y$", "$z$"])
c.configure(color_params="$z$")
fig = c.plotter.plot(figsize=1.0)

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.

###############################################################################
# You can also plot the weights or posterior if they are specified. Showing weights here.

weights = 1 / (1 + data[:, 0]**2 + data[:, 1]**2)
c = ChainConsumer().add_chain(data[:, :2], parameters=["$x$", "$y$"], weights=weights)
c.configure(color_params="weights")
fig = c.plotter.plot(figsize=3.0)

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.

###############################################################################
Beispiel #46
0
"""
===================
Blinding Parameters
===================

You can blind parameters and not show axis labels very easily!

Just give ChainConsumer the `blind` parameter when plotting. You can specify `True` to blind all parameters,
or give it a string (or list of strings) detailing the specific parameters you want blinded!

"""

import numpy as np
from numpy.random import multivariate_normal
from chainconsumer import ChainConsumer

np.random.seed(0)
data = multivariate_normal([0, 0], [[1, 0], [0, 1]], size=1000000)

c = ChainConsumer().add_chain(data, parameters=["$x$", "$y$"])
c.configure(colors=["g"])
fig = c.plotter.plot(blind="$y$")

fig.set_size_inches(2.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
Beispiel #47
0
the order of the parameters is not preserved in the dictionary.

"""
import numpy as np
from chainconsumer import ChainConsumer
from scipy.stats import multivariate_normal


x, y = np.linspace(-3, 3, 50), np.linspace(-7, 7, 100)
xx, yy = np.meshgrid(x, y, indexing='ij')
pdf = np.exp(-0.5 * (xx * xx + yy * yy / 4 + np.abs(xx * yy)))

c = ChainConsumer()
c.add_chain([x, y], parameters=["$x$", "$y$"], weights=pdf, grid=True)
fig = c.plotter.plot()
fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.

###############################################################################
# If you have the flattened array already, you can also pass this

# Turning 2D data to flat data.
xs, ys = xx.flatten(), yy.flatten()
coords = np.vstack((xs, ys)).T
pdf_flat = multivariate_normal.pdf(coords, mean=[0.0, 0.0], cov=[[1.0, 0.7], [0.7, 3.5]])
c = ChainConsumer()
c.add_chain([xs, ys], parameters=["$x$", "$y$"], weights=pdf_flat, grid=True)
c.configure(smooth=1)  # Notice how smoothing changes the results!
fig = c.plotter.plot()

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
"""
===================
Change Font Options
===================

Control tick rotation and font sizes.

Here the tick rotation has been turned off, ticks made smaller,
more ticks added, and label size increased!
"""

import numpy as np
from numpy.random import multivariate_normal
from chainconsumer import ChainConsumer


np.random.seed(0)
data = multivariate_normal([0, 1, 2], np.eye(3) + 0.2, size=100000)

# If you pass in parameter labels and only one chain, you can also get parameter bounds
c = ChainConsumer()
c.add_chain(data, parameters=["$x$", "$y^2$", r"$\Omega_\beta$"], name="Example")
c.configure(diagonal_tick_labels=False, tick_font_size=8, label_font_size=25, max_ticks=8)
fig = c.plotter.plot(figsize="column", legend=True)

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
"""
========================
Gaussian KDE and Extents
========================

Smooth marginalised distributions with a Gaussian KDE, and pick custom extents.


Note that invoking the KDE on large data sets will significantly increase rendering time when
you have a large number of points. You can also pass a float to your KDE to modify the width
of the bandpass by that factor!

You can see the increase in contour smoothness (without broadening) for when you have a
low number of samples in your chains!
"""

import numpy as np
from chainconsumer import ChainConsumer

np.random.seed(0)
data = np.random.multivariate_normal([0.0, 4.0], [[1.0, -0.7], [-0.7, 1.5]], size=3000)

c = ChainConsumer()
c.add_chain(data, name="KDE on")
c.add_chain(data + 1, name="KDE off")
c.add_chain(data + 2, name="KDE x2!")
c.configure(kde=[True, False, 2.0], shade_alpha=0.1, flip=False)
fig = c.plotter.plot(extents=[(-2, 4), (0, 9)])

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
Beispiel #50
0
"""
=====================
Flips, Ticks and Size
=====================

You can stop the second parameter rotating in the plot if you prefer squares!

Unlike the Introduction example, which shows the rotated plots, this example shows them
without the rotation.

Also, you can pass in a tuple for the figure size. We also demonstrate adding more
ticks to the axis in this example. Also, I change the colour to red, just for fun.
"""

import numpy as np
from chainconsumer import ChainConsumer

np.random.seed(0)
data = np.random.multivariate_normal([1.5, 4.0], [[1.0, 0.7], [0.7, 1.5]], size=1000000)
data[:, 0] = np.abs(data[:, 0])

c = ChainConsumer().add_chain(data, parameters=["$x_1$", "$x_2$"])
c.configure(flip=False, max_ticks=10, colors="#D32F2F")
fig = c.plotter.plot(figsize=(6, 6))

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
"""
==============
Shade Gradient
==============

Control contour contrast!

To help make your confidence levels more obvious, you can play with the gradient steepness and
resulting contrast in your contours.
"""

import numpy as np
from numpy.random import multivariate_normal
from chainconsumer import ChainConsumer

np.random.seed(0)
data1 = multivariate_normal([0, 0], [[1, 0], [0, 1]], size=1000000)
data2 = multivariate_normal([4, -4], [[1, 0], [0, 1]], size=1000000)

c = ChainConsumer()
c.add_chain(data1, parameters=["$x$", "$y$"])
c.add_chain(data2, parameters=["$x$", "$y$"])
c.configure(shade_gradient=[0.1, 3.0], colors=['o', 'k'], sigmas=[0, 1, 2, 3], shade_alpha=1.0)
fig = c.plotter.plot()

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
Because of that, you can pass any keywords to the legend call you want via `legend_kwargs`.
"""

import numpy as np
from numpy.random import multivariate_normal
from chainconsumer import ChainConsumer

np.random.seed(0)
data1 = multivariate_normal([0, 0], [[1, 0], [0, 1]], size=1000000)
data2 = data1 + 2

c = ChainConsumer()
c.add_chain(data1, parameters=["$x$", "$y$"], name="Chain 1")
c.add_chain(data2, parameters=["$x$", "$y$"], name="Chain 2")
c.configure(colors=['lb', 'g'])
fig = c.plotter.plot()
fig.set_size_inches(2.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.

###############################################################################
# If the linestyles are different and the colours are the same, the artists
# will reappear.

c = ChainConsumer()
c.add_chain(data1, parameters=["$x$", "$y$"], name="Chain 1")
c.add_chain(data2, parameters=["$x$", "$y$"], name="Chain 2")
c.configure(colors=['lb', 'lb'], linestyles=["-", "--"])
fig = c.plotter.plot()
fig.set_size_inches(2.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.

###############################################################################
summaries. If you simply want more (or less) bins than the default estimate,
if you input a float instead of an integer, the number of bins will simply scale
by that amount. For example, if the estimated picks 20 bins, and you set ``bins=1.5``
your plots and summaries would be calculated with 30 bins.

"""
import numpy as np
from numpy.random import normal, random, multivariate_normal
from chainconsumer import ChainConsumer


np.random.seed(0)
cov = 0.3 * random(size=(3, 3)) + np.identity(3)
data = multivariate_normal(normal(size=3), np.dot(cov, cov.T), size=100000)
cov = 0.3 * random(size=(3, 3)) + np.identity(3)
data2 = multivariate_normal(normal(size=3), np.dot(cov, cov.T), size=100000)
cov = 0.3 * random(size=(3, 3)) + np.identity(3)
data3 = multivariate_normal(normal(size=3), np.dot(cov, cov.T), size=100000)
cov = 0.3 * random(size=(3, 3)) + np.identity(3)
data4 = multivariate_normal(normal(size=3), np.dot(cov, cov.T), size=100000)

c = ChainConsumer()
c.add_chain(data, name="A")
c.add_chain(data2, name="B")
c.add_chain(data3, name="C")
c.add_chain(data4, name="D")
c.configure(bins=50, rainbow=True)
fig = c.plotter.plot(figsize=0.75)  # Also making the figure 75% of its original size, for fun

fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
fig = c.plotter.plot()
fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.

###############################################################################
# Or we can enable maximum closest statistics

c = ChainConsumer().add_chain(data, parameters=parameters).configure(statistics="max_shortest")
fig = c.plotter.plot()
fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.

###############################################################################
# Or we can enable maximum central statistics

c = ChainConsumer().add_chain(data, parameters=parameters).configure(statistics="max_central")
fig = c.plotter.plot()
fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.

###############################################################################
# We can also take advantage of the ability to pass lists to ChainConsumer's
# configuration to have report different statistics for different chains.
# Please note, I don't recommend you do this in practise, it is just begging
# for confusion.

c = ChainConsumer()
stats = list(c.analysis._summaries.keys())
for stat in stats:
    c.add_chain(data, parameters=parameters, name=stat.replace("_", " ").title())
c.configure(statistics=stats, bar_shade=True)
fig = c.plotter.plot()
fig.set_size_inches(4.5 + fig.get_size_inches())  # Resize fig for doco. You don't need this.
https://github.com/cpadavis/preliminize, which will add watermark to arbitrary
figures!

"""

import numpy as np
from numpy.random import multivariate_normal
from chainconsumer import ChainConsumer

np.random.seed(0)
data1 = multivariate_normal([3, 5], [[1, 0], [0, 1]], size=1000000)
data2 = multivariate_normal([5, 3], [[1, 0], [0, 1]], size=10000)


c = ChainConsumer()
c.add_chain(data1, parameters=["$x$", "$y$"], name="Good results")
c.add_chain(data2, name="Unfinished results")
fig = c.plotter.plot(watermark=r"\textbf{Preliminary}", figsize=2.0)


###############################################################################
# You can also control the text options sent to the matplotlib text call.

c = ChainConsumer()
c.add_chain(data1, parameters=["$x$", "$y$"], name="Good results")
c.add_chain(data2, name="Unfinished results")
kwargs = {"color": "purple", "alpha": 1.0, "family": "sanserif", "usetex": False, "weight": "bold"}
c.configure(watermark_text_kwargs=kwargs, flip=True)
fig = c.plotter.plot(watermark="SECRET RESULTS", figsize=2.0)