示例#1
0
        axes[row][1].plot(
                frames, 
                intercepts,
                label=voltage,
                linestyle=linestyle,
                color="red"
            )
        #axes[row][0].set_ylabel(r"Slope $a$")
        #axes[row][1].set_ylabel(r"Intercept $b$")
        axes[row][1].yaxis.tick_right()
        axes[row][1].yaxis.set_label_position("right")
for ax in axes[2]:
    ax.set_xlabel("Frame index")
#axes[1].legend(loc="center left")
axes[0][0].set_title(r"Slope $a$")
axes[0][1].set_title(r"Intercept $b$")
plt.grid(True)
plt.tight_layout()

#plt.show(); import sys; sys.exit()

from utils import save_tex
save_tex(
        __file__,
        addFigureDims=True,
        extra=set([
            #r"legend style={font=\tiny}",
            r"ticklabel style={font=\footnotesize}"
            ])
            )
    for fl in fluxes:
        selection = flux == fl
        sorting = np.argsort(frms[selection])
        ax.errorbar(
                frms[selection][sorting],
                sharpness[selection][sorting],
                yerr=uncertainty[selection][sorting],
                fmt="x-",
                label=str(fl)
                )
        ax.set_xlabel("Frames")
    if findex == 0:
        ax.set_ylabel("Edge sharpness")
    ax.set_ylim(0.1, 1.2)

plt.tight_layout()
#plt.show(); import sys; sys.exit()

from utils import save_tex
#"""
save_tex(
        __file__,
        subdir="jaw",
        addFigureDims=True,
        extra=set([
            r"legend style={font=\footnotesize}",
            r"ticklabel style={font=\footnotesize}"
            ])
        )
#"""
    ax.add_patch(
            Rectangle(
                *roi_props["rect_args"],
                ec="red",
                fill=False
                )
            )
    ax.annotate(
            "$s={}$".format(slice_index),
            (5,300),
            color="white",
            fontsize="xx-large"
            )
    #ax.set_title("{}".format(name))
    ax.set_axis_off()
    ax.grid(False)

fig.subplots_adjust(right=0.85)
cbar_ax = fig.add_axes([0.9, 0.1, 0.05, 0.8])
fig.colorbar(img, cax=cbar_ax)

# Tweak padding and save via toolbar
plt.show(); import sys; sys.exit()

from utils import save_tex
save_tex(
        __file__,
       subdir="jaw",
       addFigureDims=True
       )
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
from utils import save_tex

style.use("ggplot")
fig, ax = plt.subplots(1, 1)

for material in ["water", "lead"]:
    data = np.loadtxt(
            "../data/mass-attenuation-coeff_{}.dat".format(material),
            delimiter="  ",
            usecols=(0, 1)
            )
    ax.loglog(*data.T, label=material)
    ax.set_xlim(0.001, 20)

ax.set_xlabel(r"Photon energy, MeV")
ax.set_ylabel(r"$\mu/\rho$, cm$^2$ g$^{-1}$")
plt.legend(loc="upper right")
plt.tight_layout()

#plt.show()
save_tex(
        __file__,
        addFigureDims=True,
        extra=set([
            r"ticklabel style={font=\footnotesize}"
            ])
        )
示例#5
0
import matplotlib.pyplot as plt 
from matplotlib import style
import numpy as np 

fig = plt.figure()
style.use('ggplot')

plt.plot()
plt.grid(True)

#plt.show()

from utils import save_tex
save_tex(__file__)
示例#6
0
fig = plt.figure()
style.use('ggplot')

parameters = [
        (3.0, 3.0),
        (5.0, 1.8)
        ]
for kappa, sigma_d in parameters:
    r = kappa*sigma_d
    x = np.arange(-r, r+1)

    gaussian_kernel = np.exp(-x**2/(2.0*sigma_d**2))

    plt.plot(x, gaussian_kernel, 'o',
            markersize=2,
            label="$\\sigma_d={},\\kappa={}$".format(sigma_d, kappa)
            )
plt.xlabel('Distance from kernel center')
plt.ylabel('Weight')
plt.legend(loc="lower center")
plt.grid(True)

#plt.show(); import sys; sys.exit()

from utils import save_tex
save_tex(
        __file__,
        addFigureDims=True 
        )
                    sharpness[fm_selection][fl_selection][frms_sorting],
                    yerr=uncertainty[fm_selection][fl_selection][frms_sorting],
                    fmt=".-",
                    label=flux_str,
                    markersize=1.0
                    )
        ax.grid(True)
        ax.set_ylim(ylim)
        ax.set_xlim(200, 1039)
        ax.set_xlabel("Frames")
        if fm == 0:
            ax.set_ylabel("Edge sharpness")
        if fm == legendfm:
            print("Don't forget to set the legend location to at={(0.5,0.03)}")
            print("Also, adding 'forget plot' to the markplots of the subplot containing the legend,")
            print(r"i.e. \addplot [color0, mark=-, mark size=3, only marks, forget plot]")
            ax.legend(loc=loc)
        plt.tight_layout()

        save_tex(
                __file__,
                subdir="jaw",
                addFigureDims=True,
                suffix=suffix+str(fm),
                extra=set([
                    r"legend style={font=\tiny}",
                    r"ticklabel style={font=\footnotesize}",
                    r"legend columns=2"
                    ])
                )
    if fmode == "postfiltered" or fmode == "weighted": # 0.1639, 0.1637
        print fmode, np.mean(volume[roi])
    var1 = np.var(volume[roi])
    nl_data.append(var1)

# Plot noise level versus edge sharpness and annotate.
for es, esd, nl in zip(es_data[0], es_data[1], nl_data):
    # Different color for each dot
    plt.errorbar(es, nl, xerr=esd, fmt='o', markersize=3)

for fmode, x, y in zip(FILTER_MODES, es_data[0], nl_data):
    plt.annotate(fmode, xy=(x, y))

ax.set_ylabel("Noise level")
ax.set_xlabel("Edge sharpness")
ax.set_xlim(0.2, 1.0)
ax.set_ylim(0, 0.0011)

ax.grid(True)
#plt.show(); import sys; sys.exit()

from utils import save_tex
save_tex(
        __file__,
        subdir="johann",
        addFigureDims=True,
        extra=set([
            r"ticklabel style={font=\tiny}"
            ])
        )
示例#9
0
import numpy as np 

fig = plt.figure()
style.use('ggplot')

x, y = np.loadtxt(
        "../data/nose/csv/croppedjaw_normed_masked_volume_var-mean.csv",
        delimiter=';',
        unpack=True 
        )
# account for the normalization when loaded to ImFusionSuite.
xmin, xmax = [-1.75781,19.5312]
xrange_ = xmax - xmin

plt.plot(x*xrange_ + xmin, y, '.', markersize=1)
plt.semilogy()
plt.grid(True)
plt.xlabel("Voxel mean value")
plt.ylabel("Variance")
plt.xlim(-1,20)
plt.ylim(4e-6, 3e-4)

#plt.show()

from utils import save_tex
save_tex(
        __file__,
        addFigureDims=True,
        subdir="nose"
        )
示例#10
0
                rmses[fr_selection][fl_selection][tvGrad_sorting],
                "o-",
                markersize=1,
                label=mant_exp_from_int(fl)[2],
            )
        ax.set_title("{} frames".format(fr))
        ax.grid(True)
        ax.semilogx()
        ax.set_xlabel("TV parameter")
        if i == 0:
            ax.set_ylabel("RMSE")
            ax.legend(loc="upper center", ncol=2)

    # plt.show()
    # """
    save_tex(
        __file__,
        addFigureDims=True,
        subdir="jaw",
        suffix="-mlem" if "mlem" in file else "-sirt",
        extra=set(
            [
                r"legend style={font=\tiny}",
                r"ticklabel style={font=\tiny}"
                # r"legend columns=2"
            ]
        ),
    )

# """
示例#11
0
        ax.semilogy()

    ax.set_title(irmode)
    ax.grid(True)
    ax.set_ylim(1e-7, 0.01)
    #conserves the grid, other than ax.xaxis.set_ticks([])
    # Both approaches allow setting an xlabel
    ax.xaxis.set_ticklabels([]) 
    #ax.set_xlabel("Frames")
    if i == 0:
        ax.set_ylabel("Noise level")
        legend = ax.legend(loc="lower center", ncol=2)
plt.tight_layout()
plt.show();import sys; sys.exit()

from utils import save_tex
#"""
# legend needs to be removed from second subplot. Tweak at={(0.5,0.03)}.
save_tex(
        __file__,
        subdir="jaw", 
        addFigureDims=True,
        extra=set([
            r"legend style={font=\tiny}",
            r"ticklabel style={font=\tiny}",
            r"legend columns=2",
            r"xticklabels={,,}"
            ])
        )
#"""
示例#12
0
ax.plot(
        sigma_var[sigma_var != 0],
        var1[sigma_var != 0],
        'o',
        markersize=2
        )
ax.plot(
        0, 
        var1[sigma_var == 0],
        '*',
        markersize=4
        )
ax.set_xlim(-0.1, 3)
ax.set_xlabel("$\sigma$")
ax.set_ylabel("Noise level")
"""

plt.grid(True)

#plt.show(); import sys; sys.exit()

from utils import save_tex
save_tex(
        __file__,
        addFigureDims=True,
        extra=set([
            r"ticklabel style={font=\footnotesize}",
            r"every x tick scale label/.style={at={(1,0)},yshift=-3pt,anchor=north,inner sep=0pt}"
            ])
        )
示例#13
0
def gauss(x, *coeffs):
    A, mu, sigma = coeffs 
    return A * np.exp(-0.5 * (x-mu)**2 / sigma**2)

from scipy.optimize import curve_fit 
popt, pcov = curve_fit(gauss, x, y, p0=(540, 10800, 100))
#print popt
#print np.mean(x)
#print np.var(x)

plt.bar(x,y,width=8)
fine_x = np.arange(10400, 11200)
plt.plot(fine_x, gauss(fine_x, *popt)
        #label="Fit curve $f(x)=A\\cdot\\exp(\\frac{1}{2\\pi\\sigma^2}\ (x-\\mu)^2)$"
        )

plt.grid(True)
plt.xlim(10500, 11200)
plt.xlabel("Gray value")
plt.ylabel("Counts")
#plt.legend(loc="upper left")

#plt.show()

from utils import save_tex
save_tex(
        __file__,
        addFigureDims=True,
        draw_rectangles=True #required to draw bar plot
        )