How was the equation $E=hf$ discovered?
Was the proportional expression between energy and frequency of light $E\propto f$ discovered only by experiment? Or is there some logical(theoretical) senses affected?
Discrete spectral lines (frequencies) of atoms were known since long ago. So an emitted wave has a quite certain frequency. If an absorber has many "resonators", it is the resonance resonator who likely will absorb the wave entirely. But this exchange says nothing about the relationship of the wave energy and the wave frequency. Classically it is the amplitude square integrated over the space that gives the wave energy. So the Plank relationship is alien to classical notions. It was hard to accept and only experiments helped prove its universality.
The Plank law was first a fit bridging two experimental asymptotics. But it worked so well for different $T$ and with a unique $h$ that Plank started to "derive" this law and introduced those quanta. The original fit is one of those rare cases in Physics when the exact formula is extremely simple and can be guessed.
The relationship $E = h f$ was proposed by Max Plank in 1899 or 1900 as a way to "fix" a major problem in the existing understanding of the how light was emitted by hot bodies (the so called "ultraviolet catastrophe"). The conventional story holds that Plank did not consider this as fundamental.1
Later Albert Einstein took the idea as a way to explain the photo-electric effect in 1905, bringing the principle that light energy actually came in discrete chucks to the forefront. This work was among that cited by the committee in awarding Einstien's Nobel prize.
The discovery of Compton Scattering in 1923 gave the "photon" a firm place in modern physics.
Quantum field theories eventual came to explain the photon as an excitation of the electromagnetic field.
1 I can't say if that is true or not, but it is the way the Lore goes.