Juan Leni
Juan Leni

Reputation: 7628

How to import matplotlib pgf with colorbar into latex document

I have a matplotlib plot that has a colorbar. I am saving the figure as PGF so I can use in a latex document. Charts go into a different directory. When I import them, the colorbar is not shown.

some chart

Inside the PGF file, there are some instructions:

%% Figures using additional raster images can only be included by \input if
%% they are in the same directory as the main LaTeX file. For loading figures
%% from other directories you can use the `import` package
%%   \usepackage{import}
%% and then include the figures with
%%   \import{<path to file>}{<filename>.pgf}

I am actually using import in the way that it is described. Any idea why the colorbar png is not found?

Upvotes: 1

Views: 3876

Answers (1)

Juan Leni
Juan Leni

Reputation: 7628

I could solve it using the answer here:

https://tex.stackexchange.com/a/282110/91843

At the beginning of the document I had to put:

\newcommand\inputpgf[2]{{
\let\pgfimageWithoutPath\pgfimage
\renewcommand{\pgfimage}[2][]{\pgfimageWithoutPath[##1]{#1/##2}}
\input{#1/#2}
}}

Then I could import using:

\inputpgf{path/to/figures}{figure.pgf}

Note: Please vote his answer in Tex!

Upvotes: 4

Related Questions