nschloe / tikzplotlib

:bar_chart: Save matplotlib figures as TikZ/PGFplots for smooth integration into LaTeX.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Quiver tikzplotlib.save not working unless plt.savefig called before

SamuelePolimi opened this issue · comments

This code does not work:

import matplotlib.pyplot as plt
import tikzplotlib
import numpy as np

x, y, u, v = [np.random.normal(size=(20)) for _ in range(4)]
plt.quiver(x, y, u, v, width=2e-3, angles='xy', scale_units='xy', scale=1,)
tikzplotlib.save("file.tikz")

, by adding plt.savefig("file.pdf") right before the tikzplotlib.save, the following works correctly

import matplotlib.pyplot as plt
import tikzplotlib
import numpy as np

x, y, u, v = [np.random.normal(size=(20)) for _ in range(4)]
plt.quiver(x, y, u, v, width=2e-3, angles='xy', scale_units='xy', scale=1,)
plt.savefig("file.pdf")
tikzplotlib.save("file.tikz")

I used

  • python 3.6
  • tikzplotlib 0.9.2
  • matplotlib 3.1.1

Thanks in advance,
Samuele.

The stack of error running the first script is:

Traceback (most recent call last):
  File "/home/samuele/Projects/nopg-tpami/scripts/prova1.py", line 8, in <module>
    tikzplotlib.save("boh.tikz")
  File "/home/samuele/.conda/envs/rl/lib/python3.6/site-packages/tikzplotlib/_save.py", line 253, in save
    code = get_tikz_code(*args, filepath=filepath, **kwargs)
  File "/home/samuele/.conda/envs/rl/lib/python3.6/site-packages/tikzplotlib/_save.py", line 207, in get_tikz_code
    data, content = _recurse(data, figure)
  File "/home/samuele/.conda/envs/rl/lib/python3.6/site-packages/tikzplotlib/_save.py", line 351, in _recurse
    data, children_content = _recurse(data, child)
  File "/home/samuele/.conda/envs/rl/lib/python3.6/site-packages/tikzplotlib/_save.py", line 376, in _recurse
    data, cont = _draw_collection(data, child)
  File "/home/samuele/.conda/envs/rl/lib/python3.6/site-packages/tikzplotlib/_save.py", line 323, in _draw_collection
    return _patch.draw_patchcollection(data, child)
  File "/home/samuele/.conda/envs/rl/lib/python3.6/site-packages/tikzplotlib/_patch.py", line 91, in draw_patchcollection
    for path, ec, fc, ls, w, t, off in zip_modulo(paths, ecs, fcs, lss, ws, ts, offs):
  File "/home/samuele/.conda/envs/rl/lib/python3.6/site-packages/tikzplotlib/_patch.py", line 69, in zip_modulo
    yield tuple(seq[i % len(seq)] for seq in seqs)
  File "/home/samuele/.conda/envs/rl/lib/python3.6/site-packages/tikzplotlib/_patch.py", line 69, in <genexpr>
    yield tuple(seq[i % len(seq)] for seq in seqs)
ZeroDivisionError: integer division or modulo by zero