Bug summary
When using style context manager to apply font styles the behaviour is not predictable. Below are two examples. Overall it seems like the styling is being defined when the axis is created, and not refreshed when the style is tweaked.
Example 1If the axis is created outside the style context, then no font updates are applied when entering and saving the figure in the style context.
Code for reproduction
import matplotlib import matplotlib.pyplot as plt font_style = {'font.sans-serif': 'Bitstream Vera Sans', 'font.size': 22} fig, ax = plt.subplots() with matplotlib.pyplot.style.context(font_style): print(matplotlib.rcParams['font.sans-serif']) print(matplotlib.rcParams['font.size']) ax.set_xlabel('test') ax.set_ylabel('test') plt.savefig('example_1.png', bbox_inches='tight')
Actual outcome
Console:
['Bitstream Vera Sans']
22.0
Expected outcome
The font size should be bigger and be Bitstream Vera Sans.
Example 2Creating the figure in the context, then exiting the context and writing a new piece of text (using different settings) does not apply the correct font settings.
Code for reproduction
import matplotlib import matplotlib.pyplot as plt font_style = {'font.sans-serif': 'Bitstream Vera Sans', 'font.size': 22} with matplotlib.pyplot.style.context(font_style): fig, ax = plt.subplots() print(matplotlib.rcParams['font.sans-serif']) print(matplotlib.rcParams['font.size']) ax.set_xlabel('test') print(matplotlib.rcParams['font.sans-serif']) print(matplotlib.rcParams['font.size']) ax.set_ylabel('test') plt.savefig('example_2.png', bbox_inches='tight')
Actual outcome
Console;
['Bitstream Vera Sans']
22.0
['DejaVu Sans', 'Bitstream Vera Sans', 'Computer Modern Sans Serif', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', 'sans-serif']
10.0
Expected outcome
One axis label should be size 22 Bitstream Vera Sans, the other axis label should be size 10 DejaVu Sans.
Matplotlib version
Matplotlib was installed via pip.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4