0

Let's say I have these two arrays that I've plotted with matplotlib

Distance = [vlaue1; value2; value3...]

focus_measurement = [vlaue1; value2; value3...] [enter image description here]1

Using this code:

plt.plot(Distance, focus_measurement)
plt.xlabel('Distance (cm)'),plt.ylabel('Variance'), plt.title('Capteur')
plt.show()

Which gives this graph..

What I want to do now is to highlight the region of all the values greater than 1200 in the Variance and their equivalent in focus_measurement.

EDIT:

this is how you do it:

You add this line of code for the x axis:

plt.axvspan(180,300, facecolor="red", alpha=0.5)

Or this one for the y axis:

plt.axhspan(1200,1500, facecolor="red", alpha=0.5)

Which will give something like..

plt.plot(Distance, focus_measurement)
plt.xlabel('Distance (cm)'),plt.ylabel('Variance'), 
plt.title('Capteur')
plt.axvspan(180,300, facecolor="red", alpha=0.5)
plt.axhspan(1200,1500, facecolor="red", alpha=0.5)
plt.show()
Mourad Over Flow
  • 191
  • 1
  • 5
  • 16

1 Answers1

0

This is how you do it:

You add this line of code for the x axis:

plt.axvspan(180,300, facecolor="red", alpha=0.5)

Or this one for the y axis:

plt.axhspan(1200,1500, facecolor="red", alpha=0.5)

Which will give something like..

plt.plot(Distance, focus_measurement)
plt.xlabel('Distance (cm)'),plt.ylabel('Variance'), 
plt.title('Capteur')
plt.axvspan(180,300, facecolor="red", alpha=0.5)
plt.axhspan(1200,1500, facecolor="red", alpha=0.5)
plt.show()
Mourad Over Flow
  • 191
  • 1
  • 5
  • 16