gpt4 book ai didi

python - 未应用 Matplotlib 样式表

转载 作者:行者123 更新时间:2023-11-28 18:13:17 24 4
gpt4 key购买 nike

我一直在尝试几种样式表,但似乎没有一种适用于 Canvas 。这是我第一次使用 twinx(),所以这可能就是问题所在。我试过的代码如下 -

import pickle
import numpy as np
import matplotlib.pyplot as plt

with open("acc.pkl", "rb") as a:
acc = pickle.load(a)

with open("loss.pkl", "rb") as b:
loss = pickle.load(b)

x = np.array([point for point in range(100)])

fig, graph_1 = plt.subplots()
points_1 = np.array(acc)
graph_1.plot(x, points_1, 'b')

graph_2 = graph_1.twinx()
points_2 = np.array(loss)
graph_2.plot(x, points_2, 'r')

plt.style.use('fivethirtyeight')
plt.xlabel('epochs')
fig.tight_layout()
plt.show()

最佳答案

样式表参数在使用它们的对象创建 时应用。

例如如果你想要一个给定样式的图形和轴,你需要在之前通过plt.subplots创建它们时设置样式表。

plt.style.use('fivethirtyeight')
fig, graph_1 = plt.subplots()

关于python - 未应用 Matplotlib 样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49955603/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com