Hofstadter's Butterfly

Author

Eric W. Weisstein
August 12, 2026

This notebook downloaded from https://mathworld.wolfram.com/notebooks/Fractals/HofstadtersButterfly.nb.

For more information, see Eric's MathWorld entry https://mathworld.wolfram.com/HofstadtersButterfly.html.

©2026 Wolfram Research, Inc. except for portions noted otherwise

Illustration

Finite Harper matrices approximate the allowed energies as the magnetic flux parameter varies.

Module[{alphas,data,harperMatrix,n,neutral},n=48;alphas=N[Subdivide[0,1,240]];harperMatrix[alpha_]:=SparseArray[{Band[{1,1}]->Table[2 Cos[2 π alpha m],{m,0,n-1}],Band[{1,2}]->1,Band[{2,1}]->1},{n,n}];data=Flatten[(Thread[{ConstantArray[#1,n],Eigenvalues[harperMatrix[#1]]}]&)/@alphas,1];neutral=LightDarkSwitched[Black,White];ListPlot[data,Frame->True,Axes->False,FrameLabel->{Style["α",16,neutral,FontFamily->"Times"],Style["E",16,neutral,FontFamily->"Times",FontSlant->"Italic"]},FrameStyle->neutral,PlotStyle->Directive[neutral,PointSize[0.0018]],PlotRange->{{0,1},{-4,4}},BaseStyle->{FontFamily->"Times"}]]