Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib style sheet not being applied

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()
like image 551
S.Mandal Avatar asked May 09 '26 01:05

S.Mandal


1 Answers

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

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()
like image 62
ImportanceOfBeingErnest Avatar answered May 11 '26 14:05

ImportanceOfBeingErnest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!