Karlo
Karlo

Reputation: 1708

How to export a 3D plot using tikzplotlib and import it in LaTeX?

Consider following code (adapted from here):

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import tikzplotlib

r=np.linspace(0,1,11)
theta=np.linspace(0,2*np.pi,11)
R,Theta=np.meshgrid(r,theta)
X,Y=R*np.cos(Theta),R*np.sin(Theta)
Z=R*np.sin(Theta)*np.cos(Theta)

fig=plt.figure(1)
plt.clf()
ax=fig.add_subplot(projection='3d')
ax.plot_surface(X,Y,Z,rstride=1,cstride=1,cmap=cm.inferno,linewidth=0)
ax.set_xlabel('test here')
plt.show()

tikzplotlib.save("testfigure.tex")

which gives following figure :

enter image description here

When I import the file testfigure.tex in a LaTeX file, after having replaced

\begin{axis}[
hide x axis,
hide y axis,

by

\begin{axis}[
width=10cm,
width=10cm,

I obtain this result :

enter image description here

What can I do, in order to have the axis as in the Python figure? Or is this simply not possible with tikzplotlib?

Upvotes: 0

Views: 1179

Answers (1)

Franz Forstmayr
Franz Forstmayr

Reputation: 1300

Github Readme of tikzplotlib states 3D plots are not supported (2021).

Tikzplotlib - Github

Upvotes: 1

Related Questions