I have three arrays: time
, steps
and volume
. I want to plot how the volume
(Y-axis) changes over time
(X-axis) and demonstrate how the time
correlates with steps
(2nd X-axis).
time = np.array([1.280000e-07, 1.322240e-07, 1.364480e-07, 1.288448e-06,
1.288448e-06, 1.288448e-06, 1.292672e-06, 1.292672e-06,
1.420672e-06, 1.424896e-06, 1.429120e-06, 2.581120e-06,
2.581120e-06, 2.581120e-06, 2.585344e-06, 2.585344e-06,
2.586400e-06, 2.587456e-06, 2.603456e-06])
steps = np.arange(1,20)
volume = np.array([256., 384., 512., 512., 384., 256., 128., 0., 256., 384., 512.,
512., 384., 256., 128., 0., 32., 64., 96.])
Time values from time
are linked to the corresponding steps
values, such as step[1]
happens at time[1]
, step[2]
at time[2]
and etc.
I tried twiny()
but it seems to work only if the scale is the same between the two axes. In the plot below both axes have uniform intervals between values and are evenly distributed.
fig, ax1 = plt.subplots(1, 1, figsize=(10, 4.5), dpi=160, facecolor='w', edgecolor='k', sharey=True)
ax1.plot(t,volume)
ax2 = ax1.twiny()
ax2.set_xticks(steps)
How do I scale the steps
axis in correspondence with time
axis?