Matplotlib样式表未应用 [英] Matplotlib style sheet not being applied

查看:43
本文介绍了Matplotlib样式表未应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试几种样式表,但似乎没有一个适用于画布.这是我第一次使用 twinx(),所以也许是问题所在.我尝试过的代码如下-

I've been trying several style sheets but none of them seems to be applied to the canvas. This is the first time I'm using twinx() so maybe that's the issue. The code I have tried is below -

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()

推荐答案

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

The stylesheet parameters are applied at the time the object that uses them is created.

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

E.g. if you want to have a figure and axes in a given style, you need to set the style sheet before creating them via plt.subplots.

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

这篇关于Matplotlib样式表未应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆