我提供了一个使用 matplotlib NOT pyqt 图表的解决方案;我会留下我的答案,以防它提供任何有用的信息,因为在我尝试使用 pyqtcharts、PyQt5 等库后甚至没有任何运气导入它们,我的替代解决方案提供了一个很好的途径来避免使用已弃用的库,对我来说,立即使我的会话崩溃。
您没有提供任何代码,所以我将给出一个示例解决方案:
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.transforms as transforms
y = np.linspace(-10, 10, num = 100)
fig = plt.figure(figsize = (15, 10), num = 1, clear = True)
ax = plt.subplot(1, 1, 1)
ax.plot(np.arange(0, len(y), 1), y, color = [0, 0.5, 1], lw = 1.5)
trans = transforms.blended_transform_factory(ax.get_yticklabels()[0].get_transform(), ax.transData)
ax.text(0, 0, "{:.2f}".format(0), fontsize = 10, color = [1, 0, 0], transform = trans, ha = 'right', va = 'center')
emptyVectorForZeroLine = np.zeros([len(y), 1], dtype = float)
ax.plot(np.arange(0, len(y), 1), emptyVectorForZeroLine, color = [0, 0, 0], lw = 1)
ax.set_yticks(np.linspace(-9, 9, 10))
plt.show()
要在 y 轴上添加零刻度标签:
trans = transforms.blended_transform_factory(ax.get_yticklabels()[0].get_transform(), ax.transData)
ax.text(0, 0, "{:.2f}".format(0), fontsize = 10, color = [1, 0, 0], transform = trans, ha = 'right', va = 'center')
要在 y 轴上的零值处添加一条水平绘图线:
emptyVectorForZeroLine = np.zeros([len(y), 1], dtype = float)
ax.plot(np.arange(0, len(y), 1), emptyVectorForZeroLine, color = [0, 0, 0], lw = 1)