10000 Inconsistent font settings when changing style context · Issue #11673 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Inconsistent font settings when changin A9B5 g style context #11673
Closed
@utf

Description

@utf

Bug report

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 1

If 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

example_1

Expected outcome

The font size should be bigger and be Bitstream Vera Sans.

Example 2

Creating 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

example_2

Expected outcome

One axis label should be size 22 Bitstream Vera Sans, the other axis label should be size 10 DejaVu Sans.

Matplotlib version

  • Operating system: Bash on windows
  • Matplotlib version: 2.1.2
  • Matplotlib backend: TkAgg
  • Python version: 3.5.2

Matplotlib was installed via pip.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0