Simple exemple avec matplotlib illustrant comment utiliser axhspan et axvspan pour tracer un trait horizontal et vertical respectivement :
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x = np.arange(-4,8,0.1)
y = 6.0 / ( 1.0 + np.exp(-0.6*x) )
line, = plt.plot(x, y, '--', linewidth=2)
ax.grid(True)
plt.xlabel("x", fontsize=12)
plt.ylabel("y", fontsize=12)
ax.set_xticklabels([])
ax.set_yticklabels([])
plt.xlim(-4,8)
plt.ylim(0,7)
x1 = 3.0
x2 = 5.0
y1 = 6.0 / ( 1.0 + np.exp(-0.6*x1) )
y2 = 6.0 / ( 1.0 + np.exp(-0.6*x2) )
p = plt.axhspan(y1, y2, facecolor='0.5', alpha=0.5)
p = plt.axvspan(x1, x2, facecolor='0.5', alpha=0.5)
plt.savefig('Testaxhspan.png')
plt.show()
Recherches associées
Liens | Site |
---|---|
pylab_examples example code: axhspan_demo.py | matplotlib doc |
pyplot | matplotlib doc |