nschloe / tikzplotlib

:bar_chart: Save matplotlib figures as TikZ/PGFplots for smooth integration into LaTeX.
MIT License
2.41k stars 215 forks source link

3D plots #119

Open whllnd opened 8 years ago

whllnd commented 8 years ago

Hi,

trying to plot in 3D gives an error:

import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d
import matplotlib2tikz as tikz
pos = np.zeros((3,10))
pos[0] = np.arange(10)
ax = plt.gca(projection="3d")
ax.scatter(pos[0], pos[1], pos[2], c=np.arange(pos.shape[1]))
tikz.save("pos.tex")

results in

file encoding: UTF-8
Traceback (most recent call last):
  File "makePlots.py", line 128, in <module>
    tikz.save("../thesis/plots/pos1.tex")
  File "/home/per/.miniconda3/lib/python3.5/site-packages/matplotlib2tikz/save.py", line 146, in save
    data, content = _recurse(data, figure)
  File "/home/per/.miniconda3/lib/python3.5/site-packages/matplotlib2tikz/save.py", line 223, in _recurse
    ax = axes.Axes(data, child)
  File "/home/per/.miniconda3/lib/python3.5/site-packages/matplotlib2tikz/axes.py", line 149, in __init__
    assert yaxis_pos == 'right'
AssertionError

Is 3D plotting supported at all, or do I have to venture further? Great work, though, 2D plots are a real treat with this one!

EDIT: Forgot to say using version 0.5.14

nschloe commented 8 years ago

Should definitely; I'll look at it later.

nschloe commented 8 years ago

This is a matplotlib issue; see https://github.com/matplotlib/matplotlib/issues/7243. If you want this to work, +1 there.

svretina commented 5 years ago

is this error solved? I get the same error message when trying to save a 3d plot

Traceback (most recent `all last):
  File "./surface_fit.py", line 472, in <module>
    tikz.save("./figures/surface.tex")
  File "/usr/local/lib/python3.6/site-packages/matplotlib2tikz/save.py", line 197, in save
    code = get_tikz_code(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/matplotlib2tikz/save.py", line 160, in get_tikz_code
    data, content = _recurse(data, figure)
  File "/usr/local/lib/python3.6/site-packages/matplotlib2tikz/save.py", line 280, in _recurse
    ax = axes.Axes(data, child)
  File "/usr/local/lib/python3.6/site-packages/matplotlib2tikz/axes.py", line 150, in __init__
    assert yaxis_pos == 'right'
AssertionError
nschloe commented 5 years ago

@svretina Not solved, it's a matplotlib issue. See above.

AlexSchwabauer commented 4 years ago

@nschloe the latest reply in the issue that you linked suggests using the property _offsets3d. Is this something this library can do as long there is no official answer? Here's the link to the reply: https://github.com/matplotlib/matplotlib/issues/7243#issuecomment-581045658

nschloe commented 4 years ago

Sure, whatever works.