After working on some data in Octave, I need to export the resulting plots (made up of multiple curves and including axis labels and legends) and include them in a report.

My first choice (that I had read in this paper) was to print the figures with print -depslatex -color "-Sxdim,ydim" "name.tex" and then to import them into my Latex main file by using \input{name.tex}. However, the consequences of this solution are two, and none of them suite a proper document:

  1. If I export the file with a "random" dimension, in order to fit in my document I have to import them by using \resizebox{x\textwidth}{!}{\input{name.tex}}. The plot fits in the space I want to, but the text results scaled and is barely readable.
  2. If I manually look for the correct dimension that I need the plot to be in order to fit into the document, then the text in the legends flows out of the box and overlaps marks and axis ticks (I guess because only the text is exported as Latex and the legend box with its marks are considered part of the image).

At this point, I started looking for alternatives. I considered using Xmgr for plotting and PSTex to export the figures (at the bottom of this page), but I read that it has similar problems in dealing with legends because their size is not comprised in the output *.tex file and needs to be scaled manually.

Then I started reading the documentation of PGFplots, since I read that I could just import my figures generated through a third party software and add the legends directly in Latex inside a tikzpicture environment. However, page 253 of the manual reads that "The argument of \legend is a list of entries, one for each plot", implying that I cannot insert a legend with, say, three entries for a single imported plot (that is what I get from Octave).

All in all, I'm looking for a way to solve any one of these problems and I would really appreciate some help in this regard.

EDIT: As requested in a comment, here's a mwe showing the problems I mention.

\documentclass[11pt, a4paper, oneside]{article}
\usepackage{graphicx, subcaption, pgfplots}

    \caption{Case 1: export from Octave with "random" dimensions.}
    \caption{Case 1: export from Octave with correct dimensions.}
    \begin{axis}[legend entries={First curve, Second curve}]
    \addplot graphics [xmin=-4.4448, xmax=4.5728, ymin=-110, ymax=11.379]{plot3.png};

The plots were exported from Octave with

  1. print -depslatex -color "-S600,400" "plot1.tex";
  2. print -depslatex -color "-S225,150" "plot2.tex" while
  3. the third one was simply saved through the GUI as a png image and produced this result: enter image description here
  • 1
    You can export in the .eps format, and use the psfragx package to replace the labels. – Bernard Oct 18 '17 at 20:27
  • It would be very helpful if you could edit your question and show us the graphs that you currently have created in Octave. Then we, the helpers, have it much easier to help you, because the room for "guessing" is much smaller. – Stefan Pinnow Oct 19 '17 at 6:09
  • @StefanPinnow Sorry, I was quite in a hurry yesterday and I thought the problem to be general enough to make do without the graphs. – DavideM Oct 19 '17 at 20:16
  • @DavideM, thank you for editing the question. Now I think you are misinterpreting the manual. The sentence you quoted means, that each \addplot command can have (but must not necessarily) a legend entry (regardless of the source of the data that belong to that \addplot command. – Stefan Pinnow Oct 19 '17 at 20:34
  • For example add a legend to the example given at tex.stackexchange.com/a/355705 which is much more complicate than your use-case. – Stefan Pinnow Oct 19 '17 at 20:39

Have a look at the comments in the code on how to state legend symbols for an image included with \addplot graphics containing more than one line.

% used PGFPlots v1.15
        \addplot [
            % state here the options you need to get a correct corresponding legend entry
            % (since this is the first `\addplot' command, the options belong to the 
            %  first legend entry)
            only marks,
        ] graphics [
        % used a dummy image, because you didn't provide the original one
        ] {example-image};

        % now state with the following command all the other legend symbols
            only marks,


image showing the result of above code

| improve this answer | |

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.