tikzplotlib icon indicating copy to clipboard operation
tikzplotlib copied to clipboard

Feature Request: support rasterized=True keyword

Open jnboehm opened this issue 4 years ago • 1 comments

Matplotlib provides a keyword rasterized, which allows the user to control what should be rendered as a bitmap and what shouldn't. Unfortunately for some figures it is necessary to compromise on the quality with this since the file size otherwise explodes, for example with large scatter plots. Using matplotlib this way strikes me as a good compromise between using SVG formats and usability.

As a minmal example, here I save the same figure twice:

import matplotlib.pyplot as plt
import numpy as np

import tikzplotlib

fig, ax = plt.subplots()

rng = np.random.RandomState(99)
x, y = rng.normal(size=(2, 10000))

ax.scatter(x, y, rasterized=True)

tikzplotlib.save("foo.tikz", figure=fig)
fig.savefig("foo.pdf")

Looking at the resulting file sizes:

$ du -hs foo.*
24K	foo.pdf
356K	foo.tikz

The difference will obviously increase as the amount of scatter plots increases. I'd be happy to help with this (some time after next Wednesday), although I do not know too much about this library I'm afraid.

jnboehm avatar May 26 '20 09:05 jnboehm

I also need this feature and started a quick hack: https://github.com/senselessDev/tikzplotlib/commit/b840a4fb7936bbf9f21a8f7602becbf22123777a

It is not nice and does only support some plot types. It is a starting point at best. Unfortunately, ATM I don't have time to make it better and start a PR...

senselessDev avatar Nov 21 '21 22:11 senselessDev