我正在尝试使用 tikzplotlib 保存图形。但是,我遇到了 AttributeError:“Legend”对象没有属性“_ncol”。我目前使用 tikzplotlib 版本 0.10.1 和 matplotlib 版本 3.7.0。不使用“plt.legend()”一切正常。
下面是一个不起作用的示例:
import numpy as np
import matplotlib.pyplot as plt
import tikzplotlib
# Data
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
y3 = np.tan(x)
# Plotting
plt.figure()
plt.plot(x, y1, label='sin(x)')
plt.plot(x, y2, label='cos(x)')
plt.plot(x, y3, label='tan(x)')
plt.legend()
# Save as TikZ file
tikzplotlib.save("plot.tikz")
Run Code Online (Sandbox Code Playgroud)