Gamma correcting a sinusoidal grating

I am developing a stimulation setting wherre I present a sinusoidal grating to a subject. Because of the monitor gamma expansion by a factor of 2.2, I need to gamma compress my sinusoidal grating by a factor of 1/2.2 = 0.45. I did it programatically.

The problem is the sinusoid is distorted by the gamma power-law non-linearities. Here is what I get:

enter image description here.

However, because the monitor gamma expansion should cancel out my gamma compression, I expected to obtain an undistorted sinusoid:

enter image description here ,

Can someone explain what I am doing wrong? Do I need to programatically gamma correct my stimulus in order to compensate the monitor gamma? If so, why does not the monitor gamma restore my original undistorted sinusoid grating through cancelation?