两个轴标题在同一个轴上

问题描述 投票:0回答:1

我有一个有两个单位的向量 x 。初始部分以分钟为单位,最后部分以小时为单位。然后,我需要将 y 绘制为该 x 的函数,但对单位进行微分。这有点令人困惑,所以我画了下面的图表,让您了解我需要什么。部分数据以分钟为单位,另一部分以小时为单位,我需要将两者绘制在同一张图表上。与 y(x) 在同一张图上。 下图显示了 x 轴的两个标题。

我一直在尝试使用 matplotlib.pyplot 但仍然没有成功。我希望有某种方法可以更好地操纵轴信息。

Graph with a x-axis title for example

python matplotlib graph axis
1个回答
0
投票

这是一种方法:

import matplotlib.pyplot as plt
import numpy as np

y = np.arange(10)
x_min = np.arange(5)
x_hrs = np.arange(5,10)
x = np.concatenate([x_min, x_hrs])

plt.plot(x,y)
plt.xlabel('Time (min)                                    Time(h)')
plt.xticks([0, 2, 4, 6, 8, 10], ['00:00', '00:02', '00:04', '06:00', '08:00', '10:00'])
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.