zxdawn
zxdawn

Reputation: 1005

How to make rcParams work for all axises?

I use rcParams in one script to enlarge font size in figure with twin axis:

import numpy as np
import matplotlib.pyplot as plt

# Create some mock data
t = np.arange(0.01, 10.0, 0.01)
data1 = np.exp(t)
data2 = np.sin(2 * np.pi * t)

fig, ax1 = plt.subplots()

plt.rcParams.update({'axes.titlesize': 'large',
                 'axes.labelsize':'large', 
                 'ytick.labelsize': 'large',
                 'xtick.labelsize': 'large'})

color = 'tab:red'
ax1.set_xlabel('time (s)')
ax1.set_ylabel('exp', color=color)
ax1.plot(t, data1, color=color)
ax1.tick_params(axis='y', labelcolor=color)

ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis

color = 'tab:blue'
ax2.set_ylabel('sin', color=color)  # we already handled the x-label with ax1
ax2.plot(t, data2, color=color)
ax2.tick_params(axis='y', labelcolor=color)

plt.show()

But, plt.rcParams just works for one axis.

In this example, that is the blue ticks labels.

I want to enlarge all fonts size in the figure.

Is there any simple method to achieve it?

example

Upvotes: 1

Views: 2019

Answers (1)

Diziet Asahi
Diziet Asahi

Reputation: 40667

Your problem is that you are updating rcParams after you created the left axes (ax1)

move the line plt.rcParams.update(...) before fig, ax1 = plt.subplots()

Upvotes: 2

Related Questions