This is an important question that is not very easy to answer. Several factors play a role at both power and heart rate.
The problem with heart rate.
When the heart rate monitor was introduced for consumer use, the main goal was to increase the training efficiency. By measuring the heart rate, you got a much better idea of the impact and intensity of a workout on the body. In the era before the heart rate monitor, speed was used an an indicator of the intensity of a ride. This is obviously a very inaccurate way to determine the intensity because external circumstances play a major role. However, heart rate is also an indirect way of measuring the intensity of a workout. Heart rate is the body’s response to an effort. If this reaction is always the same, then heart rate would reflect the intensity of a workout perfectly. But it turns out that a large number of factors can influence the heart rate. Examples include stress, caffeine, altitude, recovery, sleep and time of day. All these factors affect your heart rate.
We explain this a little further. We take as an example a rider with an FTP of 250 W. When this rider cycles at a power of 200 W, this is below his maximum lactate steady state (MLSS) and he can maintain this intensity for quite a long time. Now the same rider is at high altitude (2500 meters above sea level). Contrary to what many people think there is the same amount of oxygen in the air here, only the air pressure is lower so the oxygen uptake in the lungs is lower. This means that the body has to work harder to supply the muscles with the same amount of oxygen. For this reason his heart rate is higher at the same power, and because less oxygen reaches the muscles, his FTP at altitude is also lower. The same goes for fatigue (lower heart rate at the same intensity) or caffeine consumption (higher heart rate).