Mr. T
Mr. T

Reputation: 12410

Matplotlib 2.2.2 fails to xkcdify plots

I use matplotlib 2.2.2 with Python 3.5.2

When I try to use matplotlib's xkcd function, I get a normal graph:

import matplotlib
print(matplotlib.get_cachedir())
print(matplotlib.__version__)

import matplotlib.font_manager
x = [f.name for f in matplotlib.font_manager.fontManager.ttflist if f.name.startswith("Humor")]
print(set(x))

from matplotlib import pyplot as plt
import numpy as np

plt.xkcd(scale=10, length=100, randomness=20)
plt.plot(np.sin(np.linspace(0, 10)))
plt.title('Whoo Hoo!!!')
plt.show()

Output:

/home/thatsme/.cache/matplotlib
2.2.2
{'Humor Sans'}

So, Humor Sans is installed, I deleted the font cache, just in case, as suggested by other threads, I increased the jitter parameters, but nonetheless no sign of xkcdification:

enter image description here

Strange thing is that I have Eclipse installed as a dual-boot on Ubuntu 16.04 and Windows 10, and the xkcd function fails on both systems. I would have expected that the Python and Eclipse installation significantly differs between those systems, but here we are.
Any ideas, what might be the problem?

Edit: As Hans pointed out this might be a problem specific for matplotlib 2.2.2
Even more bizarre - if I run the same script using with : without any other changes like

with plt.xkcd(scale=10, length=100, randomness=20):
    plt.plot(np.sin(np.linspace(0, 10)))
    plt.title('Whoo Hoo!!!')
plt.show()

the output is the expected xkcd figure: enter image description here

Removing the with : statement brings back the first figure. The same behaviour again on both Linux and Windows, so seemingly a matplotlib version problem.

Edit: Now that we know it is a temporary, limited bug, back to the main question - How to get rid of the white edgecolor in xkcd

Upvotes: 2

Views: 275

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339570

This is a bug purely present in matplotlib 2.2. The problem is that the garbage collector is too quick. See this comment and below.

This means that currently you need to use the xkcd style inside a context to make it work. The problem should be fixed in the next release. The code from the question hence works as expected in the current development version.

Upvotes: 2

Related Questions