diff --git a/Pipfile b/Pipfile index c61bbf9..1a87909 100644 --- a/Pipfile +++ b/Pipfile @@ -1,5 +1,6 @@ [scripts] "build:report" = "sh ./scripts/build:report.sh" +"build:graphs" = "sh ./scripts/build:graphs.sh" [packages] jupyter = "*" diff --git a/code/graphs/graph1.py b/code/graphs/graph1.py new file mode 100644 index 0000000..460b979 --- /dev/null +++ b/code/graphs/graph1.py @@ -0,0 +1,148 @@ +import matplotlib.pyplot as plt +from matplotlib import gridspec +from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, + AutoMinorLocator) +import numpy as np + + +#see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot for possible format strings + +#load data +data=np.loadtxt("./data/pi/run3-adjusted.csv") +x=data[:,0] +y=data[:,1] +ysigma=data[:,3] + +def functionP(x,I_0,deltaTheta,n2): + return I_0 * np.square( + ((np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))-n2*np.cos(np.radians(x-deltaTheta))) + /((np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+n2*np.cos(np.radians(x-deltaTheta))) +) +def functionS(x,I_0,deltaTheta,n2): + return I_0 * np.square((-n2*(np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+np.cos(np.radians(x-deltaTheta)))/(n2*(np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+np.cos(np.radians(x-deltaTheta)))) + + +#fitted values +n2=1.493 +deltaTheta=0 +I_0=2550 + + + +#for plotting functions +functionX = np.arange(0, 90, 0.01) + +#for calculating residual, swap between functionS and functionP +fitted_y = functionP(x,I_0,deltaTheta,n2) + + +fig=plt.figure() + +#per no residui swappa queste due linee, devi anche levare le altre definizioni di ax0 e tutti i riferimenti a ax1 +gs=gridspec.GridSpec(2,1,height_ratios=[4,1]) +#ax0=plt.axes() + +#graph +ax0=plt.subplot(gs[0]) + +dataplot=ax0.scatter(x,y,marker='o',s=3,color='red',label='Dati') + + +#swap between functionP and functionS +fitplot = ax0.plot(functionX,functionP(functionX,I_0,deltaTheta,n2),color='blue',linewidth='.5',label='Fit') + + +#funzione reale se la vuoi mettere alla fine, secondo me ha senso a quel punto farla a tratti o cose del genere +#realfunc = ax0.plot(functionX,functionP(functionX,I_0,deltaTheta,n2),color='blue',linewidth='.3',label='fit',ls='--') + + +#residual +ax1=plt.subplot(gs[1]) +difference=np.subtract(fitted_y,y) +residual=ax1.plot(x,difference,label='Residuo',color='green',linewidth='.5') +dataplot=ax1.scatter(x,difference,marker='o',s=3,color='green') +zero=np.empty(len(y)) +zero.fill(0) +#errorsplot = ax1.errorbar(x,zero,yerr=ysigma,fmt='none',markersize=2,color='lime',label='Errori',elinewidth=.8,capsize=1.2, alpha=0) +ax1.axhline(y=0, color='black', linestyle='--',lw=0.8) +ax1.fill_between(x, -ysigma, ysigma, alpha=0.1, color="red", label="Barre di\nerrore") + + +#cosmetic +#idk if you want title?, boscherini dice che deve essere incluso nell'area del grafico, y da 0 a 1 è dentro il grafico +ax0.set_title('Intensità del fascio $\pi$-polarizzato',x=0.5, y=0.85,fontdict={'fontsize': 11},backgroundcolor='white',bbox=dict(facecolor='white',edgecolor='black')) +lines_labels = [ax.get_legend_handles_labels() for ax in fig.axes] +lines, labels = [sum(lol, []) for lol in zip(*lines_labels)] +ax0.legend(lines, labels) + +#se vuoi la griglia +ax0.grid(True,which='minor',linewidth=.2) +ax0.grid(True,which='major') + + +ax1.grid(True,which='minor',linewidth=.2) +ax1.grid(True,which='major') + +#limiti sulle y se servono, forse va messo diverso x residui +ax0.set_ylim(-100,1200) + +ax1.set_xlim(0,90) +ax0.set_xlim(0,90) +ax1.set_ylim(-22,22) + +#codice per grafico con residui +#plt.setp(ax0.get_xticklabels(),visible=False) +plt.subplots_adjust(hspace=.3) +#qui boscherini dice di mettere il simbolo dell'unità di misura, non so se scrivere deg o mettere ° +ax1.set_xlabel("Angolo (deg)") +ax0.set_xlabel("Angolo (deg)") +#maybe V for volt instead of unità arbitraria, vedi punto 12 delle sue guidelines +ax0.set_ylabel("Intensità (un. arb.)") +ax1.set_ylabel("Residuo (un.arb)") +#1 minor tick between major ticks +ax1.xaxis.set_major_locator(MultipleLocator(5)) +ax1.xaxis.set_major_formatter(FormatStrFormatter('%d')) +ax1.xaxis.set_minor_locator(MultipleLocator(1)) +ax0.xaxis.set_major_locator(MultipleLocator(5)) +ax0.xaxis.set_major_formatter(FormatStrFormatter('%d')) +ax0.xaxis.set_minor_locator(MultipleLocator(1)) +ax1.tick_params(axis='both',direction='in',which='both') +ax0.tick_params(axis='both',direction='in',which='both') +ax0.tick_params('both', length=5, which='major',labelsize=9) +ax1.tick_params('both', length=5, which='major',labelsize=9) + +#yticks +ax0.yaxis.set_major_locator(MultipleLocator(200)) +ax0.yaxis.set_major_formatter(FormatStrFormatter('%d')) +ax0.yaxis.set_minor_locator(MultipleLocator(40)) + +#questi sono per l'asse del resiudo, vanno cambiati in base a quanto esce o quanto spazio abbimao, sempre metà minor del major se vuoi un tick in mezzo a ogni major couple +ax1.yaxis.set_major_locator(MultipleLocator(10)) +ax1.yaxis.set_minor_locator(MultipleLocator(5)) + + + + + +#codice per grafico senza residui +#ax0.set_xlabel("Angolo (deg)") +#ax0.set_ylabel("Intensità (un. arb.)") +#ax0.xaxis.set_major_locator(MultipleLocator(10)) +#ax0.xaxis.set_major_formatter(FormatStrFormatter('%d')) +#ax0.xaxis.set_minor_locator(MultipleLocator(2.5)) +# ax0.xaxis.set_ticks(np.arange(start, end, stepsize)) +# starty,endy=ax0.get_ylim() +# #step size for major ticks in y +# stepsizey=100 +# ax0.yaxis.set_ticks(np.arange(starty, endy, stepsizey)) +#ax0.tick_params(axis='both',direction='inout') + + + + + +#latex backend +plt.savefig("./build/graphs/raw-pi.pgf", bbox_inches='tight') + +#normal png +plt.savefig("./build/graphs/raw-pi.png", bbox_inches='tight') diff --git a/code/graphs/graph2.py b/code/graphs/graph2.py new file mode 100644 index 0000000..4ae962c --- /dev/null +++ b/code/graphs/graph2.py @@ -0,0 +1,148 @@ +import matplotlib.pyplot as plt +from matplotlib import gridspec +from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, + AutoMinorLocator) +import numpy as np + + +#see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot for possible format strings + +#load data +data=np.loadtxt("./data/sigma/run1-adjusted.csv") +x=data[:,0] +y=data[:,1] +ysigma=data[:,3] + +def functionP(x,I_0,deltaTheta,n2): + return I_0 * np.square( + ((np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))-n2*np.cos(np.radians(x-deltaTheta))) + /((np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+n2*np.cos(np.radians(x-deltaTheta))) +) +def functionS(x,I_0,deltaTheta,n2): + return I_0 * np.square((-n2*(np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+np.cos(np.radians(x-deltaTheta)))/(n2*(np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+np.cos(np.radians(x-deltaTheta)))) + + +#fitted values +n2=1.490 +deltaTheta=0 +I_0=1350 + + + +#for plotting functions +functionX = np.arange(0, 90, 0.01) + +#for calculating residual, swap between functionS and functionP +fitted_y = functionS(x,I_0,deltaTheta,n2) + + +fig=plt.figure() + +#per no residui swappa queste due linee, devi anche levare le altre definizioni di ax0 e tutti i riferimenti a ax1 +gs=gridspec.GridSpec(2,1,height_ratios=[4,1]) +#ax0=plt.axes() + +#graph +ax0=plt.subplot(gs[0]) + +dataplot=ax0.scatter(x,y,marker='o',s=3,color='red',label='Dati') + + +#swap between functionP and functionS +fitplot = ax0.plot(functionX,functionS(functionX,I_0,deltaTheta,n2),color='blue',linewidth='.5',label='Fit') + + +#funzione reale se la vuoi mettere alla fine, secondo me ha senso a quel punto farla a tratti o cose del genere +#realfunc = ax0.plot(functionX,functionP(functionX,I_0,deltaTheta,n2),color='blue',linewidth='.3',label='fit',ls='--') + + +#residual +ax1=plt.subplot(gs[1]) +difference=np.subtract(fitted_y,y) +residual=ax1.plot(x,difference,label='Residuo',color='green',linewidth='.5') +dataplot=ax1.scatter(x,difference,marker='o',s=3,color='green') +zero=np.empty(len(y)) +zero.fill(0) +#errorsplot = ax1.errorbar(x,zero,yerr=ysigma,fmt='none',markersize=2,color='lime',label='Errori',elinewidth=.8,capsize=1.2, alpha=0) +ax1.axhline(y=0, color='black', linestyle='--',lw=0.8) +ax1.fill_between(x, -ysigma, ysigma, alpha=0.1, color="red", label="Barre di\nerrore") + + +#cosmetic +#idk if you want title?, boscherini dice che deve essere incluso nell'area del grafico, y da 0 a 1 è dentro il grafico +ax0.set_title('Intensità del fascio $\sigma$-polarizzato',x=0.5, y=0.85,fontdict={'fontsize': 11},backgroundcolor='white',bbox=dict(facecolor='white',edgecolor='black')) +lines_labels = [ax.get_legend_handles_labels() for ax in fig.axes] +lines, labels = [sum(lol, []) for lol in zip(*lines_labels)] +ax0.legend(lines, labels) + +#se vuoi la griglia +ax0.grid(True,which='minor',linewidth=.2) +ax0.grid(True,which='major') + + +ax1.grid(True,which='minor',linewidth=.2) +ax1.grid(True,which='major') + +#limiti sulle y se servono, forse va messo diverso x residui +ax0.set_ylim(0,1200) + +ax1.set_xlim(0,90) +ax0.set_xlim(0,90) +ax1.set_ylim(-25,25) + +#codice per grafico con residui +#plt.setp(ax0.get_xticklabels(),visible=False) +plt.subplots_adjust(hspace=.3) +#qui boscherini dice di mettere il simbolo dell'unità di misura, non so se scrivere deg o mettere ° +ax1.set_xlabel("Angolo (deg)") +ax0.set_xlabel("Angolo (deg)") +#maybe V for volt instead of unità arbitraria, vedi punto 12 delle sue guidelines +ax0.set_ylabel("Intensità (un. arb.)") +ax1.set_ylabel("Residuo (un.arb)") +#1 minor tick between major ticks +ax1.xaxis.set_major_locator(MultipleLocator(5)) +ax1.xaxis.set_major_formatter(FormatStrFormatter('%d')) +ax1.xaxis.set_minor_locator(MultipleLocator(1)) +ax0.xaxis.set_major_locator(MultipleLocator(5)) +ax0.xaxis.set_major_formatter(FormatStrFormatter('%d')) +ax0.xaxis.set_minor_locator(MultipleLocator(1)) +ax1.tick_params(axis='both',direction='in',which='both') +ax0.tick_params(axis='both',direction='in',which='both') +ax0.tick_params('both', length=5, which='major',labelsize=9) +ax1.tick_params('both', length=5, which='major',labelsize=9) + +#yticks +ax0.yaxis.set_major_locator(MultipleLocator(200)) +ax0.yaxis.set_major_formatter(FormatStrFormatter('%d')) +ax0.yaxis.set_minor_locator(MultipleLocator(40)) + +#questi sono per l'asse del resiudo, vanno cambiati in base a quanto esce o quanto spazio abbimao, sempre metà minor del major se vuoi un tick in mezzo a ogni major couple +ax1.yaxis.set_major_locator(MultipleLocator(10)) +ax1.yaxis.set_minor_locator(MultipleLocator(5)) + + + + + +#codice per grafico senza residui +#ax0.set_xlabel("Angolo (deg)") +#ax0.set_ylabel("Intensità (un. arb.)") +#ax0.xaxis.set_major_locator(MultipleLocator(10)) +#ax0.xaxis.set_major_formatter(FormatStrFormatter('%d')) +#ax0.xaxis.set_minor_locator(MultipleLocator(2.5)) +# ax0.xaxis.set_ticks(np.arange(start, end, stepsize)) +# starty,endy=ax0.get_ylim() +# #step size for major ticks in y +# stepsizey=100 +# ax0.yaxis.set_ticks(np.arange(starty, endy, stepsizey)) +#ax0.tick_params(axis='both',direction='inout') + + + + + +#latex backend +plt.savefig("./build/graphs/raw-sigma.pgf", bbox_inches='tight') + +#normal png +plt.savefig("./build/graphs/raw-sigma.png", bbox_inches='tight') diff --git a/code/graphs/graph3.py b/code/graphs/graph3.py new file mode 100644 index 0000000..63a4273 --- /dev/null +++ b/code/graphs/graph3.py @@ -0,0 +1,144 @@ +import matplotlib.pyplot as plt +from matplotlib import gridspec +from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, + AutoMinorLocator) +import numpy as np + + +#see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot for possible format strings + +#load data +data=np.loadtxt("./data/pi/run3-normalised.csv") +x=data[:,0] +y=data[:,1] +ysigma=data[:,3] + +def functionP(x,I_0,deltaTheta,n2): + return I_0 * np.square( + ((np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))-n2*np.cos(np.radians(x-deltaTheta))) + /((np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+n2*np.cos(np.radians(x-deltaTheta))) +) +def functionS(x,I_0,deltaTheta,n2): + return I_0 * np.square((-n2*(np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+np.cos(np.radians(x-deltaTheta)))/(n2*(np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+np.cos(np.radians(x-deltaTheta)))) + + +#fitted values +n2=1.493 +deltaTheta=0 +I_0=1 + + + +#for plotting functions +functionX = np.arange(0, 90, 0.01) + +#for calculating residual, swap between functionS and functionP +fitted_y = functionP(x,I_0,deltaTheta,n2) + + +fig=plt.figure() + +#per no residui swappa queste due linee, devi anche levare le altre definizioni di ax0 e tutti i riferimenti a ax1 +#gs=gridspec.GridSpec(2,1,height_ratios=[4,1]) +ax0=plt.axes() + +#graph +#ax0=plt.subplot(gs[0]) + + + +#swap between functionP and functionS +plt.fill_between(functionX,functionP(functionX,0.9,deltaTheta,1.5),functionP(functionX,1.1,deltaTheta,1.53),color='orange',edgecolor='orange',alpha=0.5,label='Andamento\nprevisto') +#dataplot=ax0.scatter(x,y,marker='o',s=3,color='red',label='Dati') +fitplot = ax0.plot(functionX,functionP(functionX,I_0,deltaTheta,n2),color='blue',linewidth='.6',label='Fit\nnormalizzato') + + +#funzione reale se la vuoi mettere alla fine, secondo me ha senso a quel punto farla a tratti o cose del genere +#realfunc = ax0.plot(functionX,functionP(functionX,I_0,deltaTheta,n2),color='blue',linewidth='.3',label='fit',ls='--') + + +#residual +#ax1=plt.subplot(gs[1]) +difference=np.subtract(fitted_y,y) +#residual=ax1.plot(x,difference,label='Residuo',color='green',linewidth='.5') +#dataplot=ax1.scatter(x,difference,marker='o',s=3,color='green') + + +#cosmetic +#idk if you want title?, boscherini dice che deve essere incluso nell'area del grafico, y da 0 a 1 è dentro il grafico +ax0.set_title('Andamento del coefficiente $R_\pi$',x=0.65, y=0.9,fontdict={'fontsize': 11},backgroundcolor='white',bbox=dict(facecolor='white',edgecolor='black')) +lines_labels = [ax.get_legend_handles_labels() for ax in fig.axes] +lines, labels = [sum(lol, []) for lol in zip(*lines_labels)] +ax0.legend(lines, labels) + +#se vuoi la griglia +ax0.grid(True,which='minor',linewidth=.2) +ax0.grid(True,which='major') + + +#ax1.grid(True,which='minor',linewidth=.2) +#ax1.grid(True,which='major') + +#limiti sulle y se servono, forse va messo diverso x residui +ax0.set_ylim(0,1) + +#ax1.set_xlim(0,90) +ax0.set_xlim(0,90) +#ax1.set_ylim(-22,22) + +#codice per grafico con residui +#plt.setp(ax0.get_xticklabels(),visible=False) +plt.subplots_adjust(hspace=.3) +#qui boscherini dice di mettere il simbolo dell'unità di misura, non so se scrivere deg o mettere ° +#ax1.set_xlabel("Angolo (deg)") +ax0.set_xlabel("Angolo (deg)") +#maybe V for volt instead of unità arbitraria, vedi punto 12 delle sue guidelines +ax0.set_ylabel("$R_\pi$",fontsize='15') +#ax1.set_ylabel("Residuo (un.arb)") +#1 minor tick between major ticks +#ax1.xaxis.set_major_locator(MultipleLocator(5)) +#ax1.xaxis.set_major_formatter(FormatStrFormatter('%d')) +#ax1.xaxis.set_minor_locator(MultipleLocator(1)) +ax0.xaxis.set_major_locator(MultipleLocator(5)) +ax0.xaxis.set_major_formatter(FormatStrFormatter('%d')) +ax0.xaxis.set_minor_locator(MultipleLocator(1)) +#ax1.tick_params(axis='both',direction='in',which='both') +ax0.tick_params(axis='both',direction='in',which='both') +ax0.tick_params('both', length=5, which='major',labelsize=9) +#ax1.tick_params('both', length=5, which='major',labelsize=9) + +#yticks +ax0.yaxis.set_major_locator(MultipleLocator(0.1)) +ax0.yaxis.set_major_formatter(FormatStrFormatter('%.2f')) +ax0.yaxis.set_minor_locator(MultipleLocator(0.1/5)) + +#questi sono per l'asse del resiudo, vanno cambiati in base a quanto esce o quanto spazio abbimao, sempre metà minor del major se vuoi un tick in mezzo a ogni major couple +#ax1.yaxis.set_major_locator(MultipleLocator(10)) +#ax1.yaxis.set_minor_locator(MultipleLocator(5)) + + + + + +#codice per grafico senza residui +#ax0.set_xlabel("Angolo (deg)") +#ax0.set_ylabel("Intensità (un. arb.)") +#ax0.xaxis.set_major_locator(MultipleLocator(10)) +#ax0.xaxis.set_major_formatter(FormatStrFormatter('%d')) +#ax0.xaxis.set_minor_locator(MultipleLocator(2.5)) +# ax0.xaxis.set_ticks(np.arange(start, end, stepsize)) +# starty,endy=ax0.get_ylim() +# #step size for major ticks in y +# stepsizey=100 +# ax0.yaxis.set_ticks(np.arange(starty, endy, stepsizey)) +#ax0.tick_params(axis='both',direction='inout') + + + + + +#latex backend +plt.savefig("./build/graphs/r-pi-coefficient.pgf", bbox_inches='tight') + +#normal png +plt.savefig("./build/graphs/r-pi-coefficient.png", bbox_inches='tight') diff --git a/code/graphs/graph4.py b/code/graphs/graph4.py new file mode 100644 index 0000000..ad2e26b --- /dev/null +++ b/code/graphs/graph4.py @@ -0,0 +1,144 @@ +import matplotlib.pyplot as plt +from matplotlib import gridspec +from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, + AutoMinorLocator) +import numpy as np + + +#see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot for possible format strings + +#load data +data=np.loadtxt("./data/sigma/run1-normalised.csv") +x=data[:,0] +y=data[:,1] +ysigma=data[:,2] + +def functionP(x,I_0,deltaTheta,n2): + return I_0 * np.square( + ((np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))-n2*np.cos(np.radians(x-deltaTheta))) + /((np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+n2*np.cos(np.radians(x-deltaTheta))) +) +def functionS(x,I_0,deltaTheta,n2): + return I_0 * np.square((-n2*(np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+np.cos(np.radians(x-deltaTheta)))/(n2*(np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+np.cos(np.radians(x-deltaTheta)))) + + +#fitted values +n2=1.490 +deltaTheta=0 +I_0=1 + + + +#for plotting functions +functionX = np.arange(0, 90, 0.01) + +#for calculating residual, swap between functionS and functionP +fitted_y = functionS(x,I_0,deltaTheta,n2) + + +fig=plt.figure() + +#per no residui swappa queste due linee, devi anche levare le altre definizioni di ax0 e tutti i riferimenti a ax1 +#gs=gridspec.GridSpec(2,1,height_ratios=[4,1]) +ax0=plt.axes() + +#graph +#ax0=plt.subplot(gs[0]) + + + +#swap between functionP and functionS +plt.fill_between(functionX,functionS(functionX,0.95,deltaTheta,1.5),functionS(functionX,1.05,deltaTheta,1.53),color='orange',edgecolor='orange',alpha=0.5,label='Andamento\nprevisto') +#dataplot=ax0.scatter(x,y,marker='o',s=3,color='red',label='Dati') +fitplot = ax0.plot(functionX,functionS(functionX,I_0,deltaTheta,n2),color='blue',linewidth='.6',label='Fit\nnormalizzato') + + +#funzione reale se la vuoi mettere alla fine, secondo me ha senso a quel punto farla a tratti o cose del genere +#realfunc = ax0.plot(functionX,functionP(functionX,I_0,deltaTheta,n2),color='blue',linewidth='.3',label='fit',ls='--') + + +#residual +#ax1=plt.subplot(gs[1]) +difference=np.subtract(fitted_y,y) +#residual=ax1.plot(x,difference,label='Residuo',color='green',linewidth='.5') +#dataplot=ax1.scatter(x,difference,marker='o',s=3,color='green') + + +#cosmetic +#idk if you want title?, boscherini dice che deve essere incluso nell'area del grafico, y da 0 a 1 è dentro il grafico +ax0.set_title('Andamento del coefficiente $R_\sigma$',x=0.65, y=0.9,fontdict={'fontsize': 11},backgroundcolor='white',bbox=dict(facecolor='white',edgecolor='black')) +lines_labels = [ax.get_legend_handles_labels() for ax in fig.axes] +lines, labels = [sum(lol, []) for lol in zip(*lines_labels)] +ax0.legend(lines, labels) + +#se vuoi la griglia +ax0.grid(True,which='minor',linewidth=.2) +ax0.grid(True,which='major') + + +#ax1.grid(True,which='minor',linewidth=.2) +#ax1.grid(True,which='major') + +#limiti sulle y se servono, forse va messo diverso x residui +ax0.set_ylim(0,1) + +#ax1.set_xlim(0,90) +ax0.set_xlim(0,90) +#ax1.set_ylim(-22,22) + +#codice per grafico con residui +#plt.setp(ax0.get_xticklabels(),visible=False) +plt.subplots_adjust(hspace=.3) +#qui boscherini dice di mettere il simbolo dell'unità di misura, non so se scrivere deg o mettere ° +#ax1.set_xlabel("Angolo (deg)") +ax0.set_xlabel("Angolo (deg)") +#maybe V for volt instead of unità arbitraria, vedi punto 12 delle sue guidelines +ax0.set_ylabel("$R_\sigma$",fontsize='15') +#ax1.set_ylabel("Residuo (un.arb)") +#1 minor tick between major ticks +#ax1.xaxis.set_major_locator(MultipleLocator(5)) +#ax1.xaxis.set_major_formatter(FormatStrFormatter('%d')) +#ax1.xaxis.set_minor_locator(MultipleLocator(1)) +ax0.xaxis.set_major_locator(MultipleLocator(5)) +ax0.xaxis.set_major_formatter(FormatStrFormatter('%d')) +ax0.xaxis.set_minor_locator(MultipleLocator(1)) +#ax1.tick_params(axis='both',direction='in',which='both') +ax0.tick_params(axis='both',direction='in',which='both') +ax0.tick_params('both', length=5, which='major',labelsize=9) +#ax1.tick_params('both', length=5, which='major',labelsize=9) + +#yticks +ax0.yaxis.set_major_locator(MultipleLocator(0.1)) +ax0.yaxis.set_major_formatter(FormatStrFormatter('%.2f')) +ax0.yaxis.set_minor_locator(MultipleLocator(0.1/5)) + +#questi sono per l'asse del resiudo, vanno cambiati in base a quanto esce o quanto spazio abbimao, sempre metà minor del major se vuoi un tick in mezzo a ogni major couple +#ax1.yaxis.set_major_locator(MultipleLocator(10)) +#ax1.yaxis.set_minor_locator(MultipleLocator(5)) + + + + + +#codice per grafico senza residui +#ax0.set_xlabel("Angolo (deg)") +#ax0.set_ylabel("Intensità (un. arb.)") +#ax0.xaxis.set_major_locator(MultipleLocator(10)) +#ax0.xaxis.set_major_formatter(FormatStrFormatter('%d')) +#ax0.xaxis.set_minor_locator(MultipleLocator(2.5)) +# ax0.xaxis.set_ticks(np.arange(start, end, stepsize)) +# starty,endy=ax0.get_ylim() +# #step size for major ticks in y +# stepsizey=100 +# ax0.yaxis.set_ticks(np.arange(starty, endy, stepsizey)) +#ax0.tick_params(axis='both',direction='inout') + + + + + +#latex backend +plt.savefig("./build/graphs/r-sigma-coefficient.pgf", bbox_inches='tight') + +#normal png +plt.savefig("./build/graphs/r-sigma-coefficient.png", bbox_inches='tight') diff --git a/code/graphs/graph5.py b/code/graphs/graph5.py new file mode 100644 index 0000000..5913999 --- /dev/null +++ b/code/graphs/graph5.py @@ -0,0 +1,143 @@ +import matplotlib.pyplot as plt +from matplotlib import gridspec +from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, + AutoMinorLocator) +import numpy as np + + +#see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot for possible format strings + +#load data +data=np.loadtxt("./data/pi/run3-parabola.csv") +x=data[:,0] +y=data[:,1] +ysigma=data[:,3] + +def functionP(x,I_0,deltaTheta,n2): + return I_0 * np.square( + ((np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))-n2*np.cos(np.radians(x-deltaTheta))) + /((np.sqrt(1-np.square(((1/n2)*np.sin(np.radians(x-deltaTheta))))))+n2*np.cos(np.radians(x-deltaTheta))) +) +def functionS(x): + return 0.29*np.square(x-56.8) + +#fitted values +n2=1.490 +deltaTheta=0 +I_0=1 + + + +#for plotting functions +functionX = np.arange(0, 90, 0.01) + +#for calculating residual, swap between functionS and functionP +#fitted_y = functionS(x,I_0,deltaTheta,n2) + + +fig=plt.figure() + +#per no residui swappa queste due linee, devi anche levare le altre definizioni di ax0 e tutti i riferimenti a ax1 +#gs=gridspec.GridSpec(2,1,height_ratios=[4,1]) +ax0=plt.axes() + +#graph +#ax0=plt.subplot(gs[0]) + + + +#swap between functionP and functionS +#plt.fill_between(functionX,functionS(functionX),functionS(functionX),color='orange',edgecolor='orange',alpha=0.5,label='Andamento\nprevisto') +#dataplot=ax0.scatter(x,y,marker='o',s=3,color='red',label='Dati') +fitplot = ax0.plot(functionX,functionS(functionX),color='blue',linewidth='.6',label='Fit') +dataplot=ax0.errorbar(x,y,yerr=ysigma,fmt='o',markersize=2,color='red',label='Dati',elinewidth=.8,capsize=1.2) + +#funzione reale se la vuoi mettere alla fine, secondo me ha senso a quel punto farla a tratti o cose del genere +#realfunc = ax0.plot(functionX,functionP(functionX,I_0,deltaTheta,n2),color='blue',linewidth='.3',label='fit',ls='--') + + +#residual +#ax1=plt.subplot(gs[1]) +#difference=np.subtract(fitted_y,y) +#residual=ax1.plot(x,difference,label='Residuo',color='green',linewidth='.5') +#dataplot=ax1.scatter(x,difference,marker='o',s=3,color='green') + + +#cosmetic +#idk if you want title?, boscherini dice che deve essere incluso nell'area del grafico, y da 0 a 1 è dentro il grafico +ax0.set_title('Fit parabolico dell\'angolo di Brewster',x=0.5, y=0.9,fontdict={'fontsize': 11},backgroundcolor='white',bbox=dict(facecolor='white',edgecolor='black')) +lines_labels = [ax.get_legend_handles_labels() for ax in fig.axes] +lines, labels = [sum(lol, []) for lol in zip(*lines_labels)] +ax0.legend(lines, labels) + +#se vuoi la griglia +ax0.grid(True,which='minor',linewidth=.2) +ax0.grid(True,which='major') + + +#ax1.grid(True,which='minor',linewidth=.2) +#ax1.grid(True,which='major') + +#limiti sulle y se servono, forse va messo diverso x residui +ax0.set_ylim(-10,40) + +#ax1.set_xlim(0,90) +ax0.set_xlim(45,70) +#ax1.set_ylim(-22,22) + +#codice per grafico con residui +#plt.setp(ax0.get_xticklabels(),visible=False) +#plt.subplots_adjust(hspace=.3) +#qui boscherini dice di mettere il simbolo dell'unità di misura, non so se scrivere deg o mettere ° +#ax1.set_xlabel("Angolo (deg)") +ax0.set_xlabel("Angolo (deg)") +#maybe V for volt instead of unità arbitraria, vedi punto 12 delle sue guidelines +ax0.set_ylabel("Intensità (un. arb.)") +#ax1.set_ylabel("Residuo (un.arb)") +#1 minor tick between major ticks +#ax1.xaxis.set_major_locator(MultipleLocator(5)) +#ax1.xaxis.set_major_formatter(FormatStrFormatter('%d')) +#ax1.xaxis.set_minor_locator(MultipleLocator(1)) +ax0.xaxis.set_major_locator(MultipleLocator(5)) +ax0.xaxis.set_major_formatter(FormatStrFormatter('%d')) +ax0.xaxis.set_minor_locator(MultipleLocator(1)) +#ax1.tick_params(axis='both',direction='in',which='both') +ax0.tick_params(axis='both',direction='in',which='both') +ax0.tick_params('both', length=5, which='major',labelsize=9) +#ax1.tick_params('both', length=5, which='major',labelsize=9) + +#yticks +ax0.yaxis.set_major_locator(MultipleLocator(5)) +ax0.yaxis.set_major_formatter(FormatStrFormatter('%d')) +ax0.yaxis.set_minor_locator(MultipleLocator(1)) + +#questi sono per l'asse del resiudo, vanno cambiati in base a quanto esce o quanto spazio abbimao, sempre metà minor del major se vuoi un tick in mezzo a ogni major couple +#ax1.yaxis.set_major_locator(MultipleLocator(10)) +#ax1.yaxis.set_minor_locator(MultipleLocator(5)) + + + + + +#codice per grafico senza residui +#ax0.set_xlabel("Angolo (deg)") +#ax0.set_ylabel("Intensità (un. arb.)") +#ax0.xaxis.set_major_locator(MultipleLocator(10)) +#ax0.xaxis.set_major_formatter(FormatStrFormatter('%d')) +#ax0.xaxis.set_minor_locator(MultipleLocator(2.5)) +# ax0.xaxis.set_ticks(np.arange(start, end, stepsize)) +# starty,endy=ax0.get_ylim() +# #step size for major ticks in y +# stepsizey=100 +# ax0.yaxis.set_ticks(np.arange(starty, endy, stepsizey)) +#ax0.tick_params(axis='both',direction='inout') + + + + + +#latex backend +plt.savefig("./build/graphs/brewsters-angle.pgf", bbox_inches='tight') + +#normal png +plt.savefig("./build/graphs/brewsters-angle.png", bbox_inches='tight') diff --git a/scripts/build:graphs.sh b/scripts/build:graphs.sh new file mode 100755 index 0000000..4826290 --- /dev/null +++ b/scripts/build:graphs.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +mkdir -p ./build/graphs; +for script in ./code/graphs/*py +do + python "$script"; + echo "Building: $script..."; +done +