Where the numbers come from
Since the caves and cliffs update (1.18), each ore is placed by one or more features. Every chunk makes a set number of tries for a feature, each at a height picked either evenly between two Y levels or as a triangle that peaks in the middle of its range. The chart adds the features up for each band of 8 blocks: tries at that height times the size of the vein. The ranges, counts and vein sizes are those of Java Edition 26.3, read from the game's placed and configured features. Bedrock Edition uses the same heights.
Why diamonds are best at the bottom
The diamond triangles run from Y −144 to 16 and peak at Y −64, the bottom of the world, so half of each triangle lies below the world and the half that is left grows thicker all the way down. Bedrock fills the bottom few layers, so the recommended tunnel is at Y −58. Below Y −54, caves fill with lava instead of air, which is the price of mining that low.
Biomes that change the answer
Emeralds are placed only in mountain biomes, peaking at Y 232. Badlands get a large extra gold feature spread evenly from Y 32 to 256, so gold turns up near the surface there. Dripstone caves get a second copper feature with veins twice the size. Iron's biggest feature peaks at Y 232, which only the highest mountain peaks reach. Basalt deltas in the Nether get twice the gold and quartz. These extras show in the chart in a second colour.
What the chart leaves out
Some features drop part or all of their ore where it would touch air: all of buried diamonds, lapis and ancient debris, and half of small diamond veins, gold and lower coal. So cave walls show less than the rock holds, and strip mining through solid stone finds more. The chart counts every try as if it were buried. Ore veins (the huge copper and iron ribbons) are a separate system and are not drawn.
Questions
What is the best Y level for diamonds?
Y −58 in Java and Bedrock: diamonds get more common the deeper you go, and Y −58 is the lowest a tunnel can run clear of bedrock. Y −53 keeps you above the lava-filled caves for about one diamond in twenty fewer.
What Y level is ancient debris at?
Most of it is between Y 8 and 24, peaking at Y 16, so mine at Y 15. A thin spread of single blocks goes up to Y 119. You need a diamond or netherite pickaxe.
Where is iron most common?
High in mountains, around Y 232, if the mountain is that tall. Underground, Y 16 is best.
Is this the same in every version?
No. The heights changed in 1.18 (caves and cliffs), when the world grew down to Y −64, and have stayed the same since; that is the default view, checked against Java Edition 26.3, and Bedrock matches it. Switch to 1.17 and older for the old world (Y 0 to 255), where diamonds, redstone and gold sit low and are best mined at Y 11. The Nether ores have not changed since 1.16.
Why is the best height not always the longest bar?
Hatched bars are ore that only some places get: a biome such as badlands, or the upper coal and iron that is placed everywhere but only exists where mountains rise that high. The best height is picked from the ore every world has. Ores spread evenly, such as Nether quartz, have equal bars, so the best height is the one that also passes another ore.
Does Fortune help?
Yes for every ore here but ancient debris. Fortune III averages 2.2 times the drops from diamond, coal, emerald, quartz and raw iron, copper and gold ore.