Skip to content
Advertisement

Is it possible to export 3D charts from MatPlotLib to TikZ?

I am trying to export a 3D diagram from Matplotlib to TikZ, using import tikzplotlib. This is the code executed in Jupyter NoteBook:

JavaScript

The resulting papon.tex file shows the following when compiled:

JavaScript

Missing any configuration or code modification? Or, simply, is it not possible to correctly export a 3D chart -with these characteristics- to TikZ?

Advertisement

Answer

The answer is yes to both questions.

The first problem is that you save the figure after show, which consumes the plot, and you save an empty new plot thereafter. The plot gets exported when you remove the following line:

JavaScript

However, the second problem is that 3d plots are indeed not supported. See the tikzplotlib documentation:

Of course, not all figures produced by matplotlib can be converted without error. Notably, 3D plots don’t work.

The output of your example above looks like the following, and the tikz output is a 2d plot. So there is no quick solution to turn that into the desired plot:

Example output

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement