mplcyberpunk icon indicating copy to clipboard operation
mplcyberpunk copied to clipboard

Savefig saves only background color

Open miroslavtushev opened this issue 3 years ago • 2 comments

Is there a fix for it? I'd like to be able to save my figs in higher dpi. But for some reason it only saves as a dark rectangle of the background color.

miroslavtushev avatar Nov 14 '21 18:11 miroslavtushev

Hi @miroslavtushev, could you provide a minimum working example?

dhaitz avatar Aug 11 '22 21:08 dhaitz

If I'm understanding your problem correctly, I was getting the exact same issue and intermittently - some charts generated fine, some had the cyberpunk-styled background and line objects but the chart area, axis text, title were not cyberpunk-styled: image

Other charts looked well: image

My setup was using a multiprocessing Pool() object to build many charts at once. On each process, the following code was run:

fig, ax = pl.subplots(figsize=(15, 8))
if self.dark_mode:
      pl.style.use("cyberpunk")
else:
      pl.style.use("bmh")

To fix the issue, I simply moved the fig, ax assignment below the pl.style.use block:

if self.dark_mode:
      pl.style.use("cyberpunk")
else:
      pl.style.use("bmh")
fig, ax = pl.subplots(figsize=(15, 8))

For some reason doing the pl.style.use command only once before the Pool().starmap() didn't work. Presumably, each spawned process works with a fresh unaltered instance of matplotlib - this is speculation, my understanding here is not good.

eoinmarron avatar Jun 28 '23 10:06 eoinmarron