首页 > 解决方案 > 使用 matplotlib 和 numpy 在图中获得“更宽”的分辨率?

问题描述

我昨天刚开始使用 python,因为它似乎是我们任务的一个很好且简单的解决方案。我们正在制作一个记录器,它将监控该领域的电池充电器和其他设备的长期测试。

现在我正在使用由数字生成器制作的模拟数字,我们很快就会有一些实际的和更偶数的数字可以使用,但实际的掌握让我担心,因为它是如此压缩。有没有办法“加宽”x轴,提高分辨率,从而拉伸图形?

import numpy  as np 
import matplotlib.pyplot as plt
    
data = np.loadtxt('test.txt')

x = data[:, 0]
y = data[:, 1]
y2 = data[:, 2]
y3 = data[:, 3]

fig = plt.figure(facecolor = ("Pink"))

ax = fig.add_subplot(111)

ax.plot(x, y, '--', label='Voltage')
ax.plot(x, y2, '-.', label='Current')

ax2 = ax.twinx()
ax2.plot(x, y3,'g:', label='Temperature')

fig.legend(edgecolor = ("DarkBlue"), facecolor = ("LightBlue"), loc="upper right", bbox_to_anchor=(1,1), bbox_transform=ax.transAxes)

ax.set_title("Test Surveillance", color = ("Purple"))    
ax.set_xlabel('Milliseconds', color = ("LightGreen"))
ax.set_ylabel('Volts and Amps', color = ("DarkGrey"))
ax2.set_ylabel('Celsius', color = ("LightBlue"))

plt.show()

忽略配色方案,这是为了测试和惹恼我的朋友。

这是它的样子。

标签: pythonnumpymatplotlibgraph

解决方案


推荐阅读