matplotlib的使用——secondary axis次坐标轴的使用 次坐标轴显示的常用函数 plt.subplots() plt.subplots()是一个函数,返回一个包含figure和axes对象的元组。因此,使用fig,ax = plt.subplots()将元组分解为fig和ax两个变量。 01 02 03 04 05 06 07 08 09 plt.subplots( nrows=1, ncols=1, sharex=...
ax1.set_xlabel('X Axis Title') ax1.set_ylabel('Y1 Axis Title') ax1.set_title('Primary Axis') # 在次坐标轴上绘制第二个数据集 ax2.plot(x, y2) ax2.set_xlabel('X Axis Title') ax2.set_ylabel('Y2 Axis Title') ax2.set_title('Secondary Axis') # 将次坐标轴与主坐标轴关联起来...
参考:How to Add a Y-Axis Label to the Secondary Y-Axis in Matplotlib Matplotlib是Python中最流行的数据可视化库之一,它提供了丰富的绘图功能,能够创建各种类型的图表。在数据可视化过程中,我们经常需要在一个图表中展示多个数据系列,有时这些数据系列的单位或数量级可能不同。在这种情况下,使用双Y轴(主Y轴...
import matplotlib.pyplot as plt fig, ax1 = plt.subplots() x = [1, 2, 3, 4, 5] y1 = [10, 20, 15, 25, 30] y2 = [100, 150, 120, 180, 200] ax1.plot(x, y1, color='r') ax1.set_ylabel('Primary Axis', color='r') ax2 = ax1.secondary_yaxis('right') ax2.plot(x...
41、使用辅助 Y 轴来绘制不同范围的图形 (Plotting with different scales using secondary Y axis) 如果要显示在同一时间点测量两个不同数量的两个时间序列,则可以在右侧的辅助Y轴上再绘制第二个系列。 42、带有误差带的时间序列 (Time Series with Error Bands) ...
我们在作图时还会遇到一些共轴图像,即图像上具有多个函数图像,函数图像横坐标值数据相同,但是纵坐标值不同,此处进行次坐标轴(secondary axis)的简单讲述: importmatplotlib.pyplotaspltimportnumpyasnp x = np.arange(0,10,.1) y_1 =0.05*x**2y_2 = -1*y_1 ...
41 使用辅助 Y 轴来绘制不同范围的图形 (Plotting with different scales using secondary Y axis) 42 带有误差带的时间序列 (Time Series with Error Bands) 43 堆积面积图 (Stacked Area Chart) 44 未堆积的面积图 (Area Chart UnStacked) 45 日历热力图 (Calendar Heat Map) 46 季节图 (Seasonal Plot) ...
41、使用辅助 Y 轴来绘制不同范围的图形 (Plotting with different scales using secondary Y axis) 如果要显示在同一时间点测量两个不同数量的两个时间序列,则可以在右侧的辅助Y轴上再绘制第二个系列。 42、带有误差带的时间序列 (Time Series with Er...
在这个示例中,我们使用twiny()函数创建了一个新的非对称轴对象ax2,并使用set_position()函数将其位置设置为与主要轴相同。然后,我们使用set_xlabel()函数设置非对称轴的标签为"Secondary X-axis"。最后,我们使用新创建的非对称轴对象ax2绘制了次要数据。
# 设置图像的上边、右边axis为无色 ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') # 设置x轴坐标在下部 ax.xaxis.set_ticks_position('bottom') # 设置x轴位于图像y=0处 ax.spines['bottom'].set_position(('data', 0)) # 设置x轴坐标在左部 ax.yaxis.set_ticks...