Ajouter un second axes des abscisses sous matplotlib (source)
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twiny()
X = np.linspace(0,1,1000)
Y = np.cos(X*10)
ax1.plot(X,Y)
ax1.set_xlabel(r"Original x-axis: $X$")
new_tick_locations = np.array([.2, .5, .9])
def tick_function(X):
V = 1/(1+X)
return ["%.3f" % z for z in V]
ax2.set_xticks(new_tick_locations)
ax2.set_xticklabels(tick_function(new_tick_locations))
ax2.set_xlabel(r"Modified x-axis: $1/(1+X)$")
plt.ylim(-1.0,1.0)
plt.savefig('ShareAxes_03.png')
plt.show()
Recherches associées
Liens | Site |
---|---|
api example code: two_scales.py | Matplotlib Doc |
api example code: fahrenheit_celsius_scales.py | Matplotlib Doc |
pylab_examples example code: shared_axis_demo.py | Matplotlib Doc |
Plotting two graphs that share an x-axis in matplotlib | stackoverflow |
pylab_examples example code: shared_axis_demo.py | stackoverflow |
In matplotlib, how do you display an axis on both sides of the figure? | stackoverflow |
How to add a second x-axis in matplotlib | stackoverflow |