Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Style configuration changing behavior of savefig #9671

Copy link
Copy link
Closed
@jasonrobwebster

Description

@jasonrobwebster
Issue body actions

Hi,

I recently upgraded to Matplotlib 2.1.0 and for some reason my fig.savefig functionality has changed. Basically, it now requires a bytes-like object whenever a certain style file is used. Running the following code:

import numpy as np
import matplotlib.pyplot as plt
plt.style.use('aps')

x = np.linspace(0, 1, 100)
y = x**2

plt.plot(x, y)
fig = plt.gcf()

fig.savefig('test.pdf')

with the style configuration file 'aps' set to:

font.family	: serif
font.serif	: Times
font.size	: 8.0

text.usetex	: True

xtick.labelsize	: 8
xtick.direction	: in
xtick.major.size: 3

ytick.labelsize	: 8
ytick.direction	: in
ytick.major.size: 3

axes.labelsize	: 8
axes.titlesize	: 8

legend.fontsize	: 7

lines.linewidth	: 1
lines.markersize: 2

figure.figsize	: 3.417, 2.112
figure.dpi	: 100

figure.subplot.left	: 0.133
figure.subplot.right	: 0.99
figure.subplot.top	: 0.97
figure.subplot.bottom	: 0.16

savefig.dpi	: 600

I get

TypeError: a bytes-like object is required, not 'str'

at the line that involves the fig.savefig line. Weirdly, removing plt.style.use('aps') removes this error (but gives me the ugly default style).

Fixing this is simple enough on my side (replace the string with the bytes like obj), but this shouldn't be occurring in fig.savefig - thought I would bring it up.

Important info:
MPL version: 2.1.0
System: Windows 7 Ultimate
Tex backend is MikTex 2.9

Python version:
'3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)]'

Regards,
jrw

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.