diff --git a/triangle_creation_frequency_plots.m b/triangle_creation_frequency_plots.m index 33faa20593f5ca3b6421202a3ce17d06ac7f7ef7..580e96a882266b7d9b86abaa786066d0e78d864b 100644 --- a/triangle_creation_frequency_plots.m +++ b/triangle_creation_frequency_plots.m @@ -79,26 +79,99 @@ hcol=GraphicsGrid[Transpose[{{h1,h2,h3},{h1zoomed,h2zoomed,h3zoomed}}]] Export[NotebookDirectory[]<>"plots/triangle_creation_frequencies_log.pdf",hcol] -(* ::Subsection:: *) -(*Test with 'Callout' labels*) +(* ::Section:: *) +(*Canonical dataset*) + + +(* Taken from stackoverflow *) +ClearAll[chartColors]; +chartColors::usage="plotColors[plotType,plotTheme] gives a list of the colors used in a plot when several curves are drawn. Here plotType is, for example, Plot or ListLogPlot while plotTheme may be \"Scientific\", \"Classic\" etc."; +chartColors[chartType_,plotTheme_]:=("ChartDefaultStyle"/.(Method/.Charting`ResolvePlotTheme[plotTheme,chartType]))/.Directive[x_,__]:>x +cl1=chartColors[Histogram,$PlotTheme] + + +gsraw=Import[NotebookDirectory[]<>"data/graphdata_canonical_creationfreqs.m"]; +(* gsraw=SortBy[gsraw,{#[[1,1]]&,#[[1,2]]&}]; (* Sort by n and then by tau. The {} forces a *stable* sort because otherwise Mathematica sorts also on triangle count and other things. *) *) -createCalloutPlot[data_]:=Module[{h,hl,bcdata,llp}, -h=Histogram[data,{-20.5,20.5,1},{"Log","Probability"},PlotRange->All,ImageSize->280]; -hl=HistogramList[data,{-20.5,20.5,1},"Probability"]; -bcdata=Map[If[#>=0.01,Callout[#,NumberForm[#,{2,3}]],Clip[#,{10^-5,2}]]&,hl[[2]]]; -llp=ListLogPlot[bcdata,PlotStyle->None,DataRange->{-20,20}]; +gdata=gsraw; +(* Data format: *) +(* gdata[[ tau index , datatype index ]] *) +(* datatype index: +1: {n,tau} +2: {{delta1, freq1}, {delta2, freq2}, ... } +3: {successful moves, move attemps} +*) + + +ticks={{1,1}}~Join~Map[{10^-#,Superscript[10,-#]}&,Range[1,9]]; +histogramData=Map[WeightedData[#[[All,1]],#[[All,2]]]&,gdata[[All,2]]]; +largeHistogram=Histogram[histogramData,{-100-0.5,100+0.5,1},{"Log","Probability"}, +PlotRange->{Automatic,Automatic}, +ChartLegends->Placed[{"\[Tau] = 2.1","\[Tau] = 2.5","\[Tau] = 2.9"},Scaled[{0.8,0.75}]], +ChartStyle->cl1, +FrameTicks->{{ticks,None},{Automatic,None}}, +PlotLabel->"n = 10000", +FrameLabel->{"net triangles created by a switch","Probability"}, +Frame->True,ImageSize->265,AspectRatio->1] + + +Export[NotebookDirectory[]<>"plots/triangle_creation_frequencies_large.pdf",largeHistogram] + + +createCalloutPlotNew[freqs_,bottomTicks_,epilog_,color_]:=Module[{total,plotrange,ticks,h,probs,cpos,callouts,llp,range=501}, +total=Total[freqs[[All,2]]]; +plotrange={{-7,7},{freqs[[Floor[Length[freqs]/2]-3,2]]/total,0.3+Max[freqs[[All,2]]]/total}}; +ticks={{1,1}}~Join~Map[{10^-#,Superscript[10,-#]}&,Range[1,4]]; +h=Histogram[WeightedData[freqs[[All,1]],freqs[[All,2]]],{-range-0.5,range+0.5,1},{"Log","Probability"}, +PlotRange->plotrange, +PlotRangeClipping->True, +ChartStyle->color, +ImagePadding->{{1,30},{If[bottomTicks==True,15,0.5],0.5}}, +Epilog->epilog, +FrameTicks->{{None,ticks},{bottomTicks,None}}, +Frame->True,ImageSize->145]; + +probs=Select[freqs,Abs[#[[1]]]<=2&]; +cpos[i_]:=\!\(\* +TagBox[GridBox[{ +{"\[Piecewise]", GridBox[{ +{"Before", +RowBox[{"i", "<", "0"}]}, +{"After", +RowBox[{"i", ">", "0"}]}, +{"Automatic", "True"} +}, +AllowedDimensions->{2, Automatic}, +Editable->True, +GridBoxAlignment->{"Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}, "Items" -> {}, "ItemsIndexed" -> {}}, +GridBoxItemSize->{"Columns" -> {{Automatic}}, "ColumnsIndexed" -> {}, "Rows" -> {{1.}}, "RowsIndexed" -> {}, "Items" -> {}, "ItemsIndexed" -> {}}, +GridBoxSpacings->{"Columns" -> {Offset[0.27999999999999997`], {Offset[0.84]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {Offset[0.2], {Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {}, "ItemsIndexed" -> {}}, +Selectable->True]} +}, +GridBoxAlignment->{"Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}, "Items" -> {}, "ItemsIndexed" -> {}}, +GridBoxItemSize->{"Columns" -> {{Automatic}}, "ColumnsIndexed" -> {}, "Rows" -> {{1.}}, "RowsIndexed" -> {}, "Items" -> {}, "ItemsIndexed" -> {}}, +GridBoxSpacings->{"Columns" -> {Offset[0.27999999999999997`], {Offset[0.35]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {Offset[0.2], {Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}, "Items" -> {}, "ItemsIndexed" -> {}}], +"Piecewise", +DeleteWithContents->True, +Editable->False, +SelectWithContents->True, +Selectable->False]\); +callouts=Map[Callout[{#[[1]],#[[2]]/total},NumberForm[N[#[[2]]/total],{2,3}],cpos[#[[1]]]]&,probs]; +llp=ListLogPlot[callouts,PlotStyle->None,PlotRange->plotrange]; Show[h,llp] ] -histograms3=Map[createCalloutPlot[Flatten[#]]&,differences,{2}]; - -(* TODO: Somehow the values of these histograms do not match the ones above!!! ????? *) +histograms3={ +createCalloutPlotNew[gdata[[1,2]],None,Text["\[Tau] = 2.1",Scaled[{0.85,0.9}]],cl1[[1]]], +createCalloutPlotNew[gdata[[2,2]],None,Text["\[Tau] = 2.5",Scaled[{0.85,0.9}]],cl1[[2]]], +createCalloutPlotNew[gdata[[3,2]],True,Text["\[Tau] = 2.9",Scaled[{0.85,0.9}]],cl1[[3]]] +}; +plotcol=Column[histograms3,Spacings->0] -Show[histograms3[[2]],PlotLabel->"n=1000, \[Tau]=2.2"] -Show[histograms3[[5]],PlotLabel->"n=1000, \[Tau]=2.5"] -Show[histograms3[[8]],PlotLabel->"n=1000, \[Tau]=2.8"] +combiplot=Row[{largeHistogram,plotcol}] +Export[NotebookDirectory[]<>"plots/triangle_creation_frequencies_combiplot.pdf",combiplot]