2

I was fiddling with how to plot raw signals to LaTeX and it turned out that there is no good solution (tikzexternalize, R+kniter, matlatb2tikz are cool but exhaust TeX memory if is really raw data)... Anyway, I decided to go with MATLAB right away and export the plots as PDFs without labels or ticks, which I intended to add/draw on to of the image. Now there's the problem:

How to draw an invisible frame and tick marks? I need the ticks for the ticklabels so hide axis is not an option. I feel that this is some pgfplot style-thing, which is totally out of my skills.

\documentclass{article}
\usepackage{pgfplots}

\pgfplotsset{compat=1.17}
\begin{document}
    \begin{figure}
        \begin{tikzpicture}
        \node[anchor=south west,inner sep=0cm] at (0,0) {\includegraphics[width=\textwidth]{constant-plot.png}};
        \begin{axis}[
                scale only axis,
                width = 9.65cm,
                height = 7.93cm,
                xshift=1.84cm,
                yshift=1.47cm,
                xmin=-0.1,
                xmax=1.1,
                ymin=0.05,
                ymax=0.7,
                ytick={0.2,0.4,...,0.6},
                color=green,
                every tick/.style={green}
                ]
        \end{axis}
        \end{tikzpicture}
    \end{figure}
\end{document}

I just took a png from pgfplots.net.

I have no idea if that is a proper way to link external graphics with Tex-based fonts/labeling but I don't see a different option.

1
  • I doubt that your approach is really feasible if you have more than two plots! If i want to visualize huge datasets i always end up using the combination of R, ggplot2, tikzdevice and knitr. The resulting plots integrate well into the general layout of the document. If you mourn about long compile times you have to read the knitr documentation more carefully. knitr is able to cache your chunks. If you use this feature compile times are even reduced compared to a document with lots of inline pgfplots. – user1146332 Apr 3 '20 at 17:14
2

Just add axis line style={opacity=0}.

\documentclass{article}
\usepackage{pgfplots}

\pgfplotsset{compat=1.17}
\begin{document}
    \begin{figure}
        \begin{tikzpicture}
        \node[anchor=south west,inner sep=0cm] at (0,0)
         {\includegraphics[width=\textwidth]{example-image-duck}};
        \begin{axis}[axis line style={opacity=0},
                scale only axis,
                width = 9.65cm,
                height = 7.93cm,
                xshift=1.84cm,
                yshift=1.47cm,
                xmin=-0.1,
                xmax=1.1,
                ymin=0.05,
                ymax=0.7,
                ytick={0.2,0.4,...,0.6},
                color=green,
                every tick/.style={green}
                ]
        \end{axis}
        \end{tikzpicture}
    \end{figure}
\end{document}

enter image description here

However, from your description you may be looking for 4.3.7 Using External Graphics as Plot Sources.

6
  • I don't like the color electric green!!!! :-) There is not a good contrast with the gray background. – Sebastiano Apr 3 '20 at 17:04
  • 1
    @Sebastiano Then you should be glad that this answer shows how to at least remove the axis lines of this color. ;-) – user194703 Apr 3 '20 at 17:05
  • In fact I have evaluated it positively immediately...and then I have inserted the comment :-). Obviously it is a personal taste the color. – Sebastiano Apr 3 '20 at 17:06
  • 1
    yes, exactly! axis line style={opacity=0},every tick/.style={opacity=0} did the job =) – max Apr 3 '20 at 17:09
  • 2
    @max No, it is the pgfplots manual. – user194703 Apr 3 '20 at 17:14
1

Disclaimer : My answer is more related to the problem of plotting large chunks of data than the technical resolution of the OP. If felt irrelevant, I will happily remove it.

For my thesis, I had quite a similar issue. I developped an overlay based on the matlab2tikz script, unfortunately I can not share it at the moment. However I can help you with the overall strategy I used.

The problem :

  • The main issue with raw data is that you tend to overflow tikz or pgfplots capabilities
  • However, you do not want matlab to plot the axis, legends or labels, otherwise you wouldn't ask this question.

The strategy :

  • Let matlab do the heavy lifting and create the raw plot then remove hide the axis and associated graphics. For this operation, I used the export_fig package, which has the ability to export png plots without most flaws of the matlab printing process.
  • Insert the printed image in a pgfplots axis using a graphics plot

    \addplot[] graphics[xmin=...,xmax=...,ymin=...,ymax=...] {path/to/your/picture};

as described in the pgfplots manual section 4.3.7 (v1.16)

With my custom script what I basically do is

  1. Plot everything
  2. Set all axis properties to manual
  3. Hide the plot of the data and export it with matlab2tikz
  4. Show the plot of the data, hide the axis and print with export_fig
  5. Edit the latex document to add the \addplot graphics
  6. Enjoy
1
  • interesting approach. I'll check this one – max Apr 4 '20 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.