Cadair / texfigure

A figure manager for PythonTeX
http://texfigure.rtfd.org/
BSD 3-Clause "New" or "Revised" License
6 stars 4 forks source link

TeXFigure renders matplotlib figure repr instead of texfigure.Figure.repr_figure #3

Closed wtbarnes closed 5 years ago

wtbarnes commented 5 years ago

Instead of the figure in the document, I get the matplotlib Figure repr, i.e. the memory address of the or what you get when you just print a Figure at the command line.

Version Info

Python: 3.6.4 TeXLive 2018 pythontex: 0.16 texfigure: master matplotlib: 2.2.2

MWE

test_texfigure.tex

\documentclass{article}
\usepackage{pythontex}
\usepackage{graphicx}
\begin{document}
\begin{pycode}[manager]
import texfigure
manager = texfigure.Manager(pytex,'./')
\end{pycode}
\begin{pycode}[manager]
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca()
ax.plot([1,2],[3,4])
Fig = manager.save_figure('Fig', fig)
Fig.caption = 'This is the caption'
\end{pycode}
\py[manager]|Fig|
\end{document}

and the resulting document looks like this,

image
Cadair commented 5 years ago

I think you need this block: https://github.com/Cadair/texfigure/blob/master/examples/texfigure_intro.tex#L45 specifically the pytex.formatter = texfigure.repr_latex_formatter line.

Also depending on your version of pythontex (i.e. if it has the patch for gpoore/pythontex#65 or not) you will need this: https://github.com/Cadair/texfigure/blob/master/examples/texfigure_intro.tex#L7 block as well. (I think that might be for the mpl latex config and not to fix the repr now I think about it)... :thinking:

wtbarnes commented 5 years ago

Thanks! I needed that last patch as well.

Cadair commented 5 years ago

It's also worth noting that gpoore/pythontex#66 would render the pytex.formatter line redundant as well.