This is measured using a radiofrequency anechoic chamber in which you can mechanically move the antenna under test through angles theta and phi while it transmits a signal with a known power level, and receive the signal using a simple dipole antenna with well-known gain at the frequency of interest. You measure the received signal amplitude as the antenna under test is moved through each pair of (theta, phi), calculate the transmitting antenna gain and generate a polar plot of the gain as required in 2 or 3 dimensions.