Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple x-axis, which are nonlinear to each other

I am trying to plot a figure with two x-axis, which are non-linear to each other, with matplotlib. The plot I want to get is like this:

Plot

Basically, the age is dependent on red shift. It's non linear and need to be calculated. I want to make both age and red shift as x-axis. How can I make it?

like image 470
Fxyang Avatar asked Oct 06 '22 01:10

Fxyang


1 Answers

The function twiny() may be what you're looking for.

import matplotlib.pyplot as plt
plt.loglog(range(100))
ax1 = plt.gca()
ax2 = ax1.twiny()
ax2.set_xticks([100,80,50])
ax2.set_xticklabels(['0','1','2'])
ax1.set_xlabel('redshift')
ax2.set_xlabel('age')
plt.show()

example plot for twiny() function

like image 103
Kyler Brown Avatar answered Oct 09 '22 13:10

Kyler Brown