News for hackers. Stuff that matters.
Re:High quality graphics for Latex documents: The Matlab route by leephillips on Friday March 17, 2017 @08:25AM (#13893403)
Gnuplot is designed to work with LaTeX. If you want a unified appearance, with textual elements on the graph typeset by TeX, then that workflow is built-in to gnuplot.

You can also use TikZ to call gnuplot from within the LaTeX document, or generate TikZ code from within gnuplot.

A very brief introduction:

https://lwn.net/Articles/628537/

Re:High quality graphics for Latex documents: The Matlab route by semi-extrinsic on Friday March 17, 2017 @08:55AM (#13893566)
You can also use PGFPlots, a plotting tool built into LaTeX (using PGF/Tikz).

http://pgfplots.sourceforge.net/

It delivers nice vector graphics plots, and since it's in your .tex file, it automatically picks up any and all styling changes you have made in the preamble. You can have it re-render plots on each LaTeX compilation, or just conditionally re-render plots if the data has changed.

(As always, latexmk [ http://mg.readthedocs.io/latexmk.html ] comes highly recommended for automating the compilation of LaTeX documents.)

Re:High quality graphics for Latex documents: The Matlab route by JohnHammersley on Friday March 17, 2017 @09:15AM (#13893650)
There's also a nice gallery of online pgfplot examples at http://pgfplots.net
Re:High quality graphics for Latex documents: The Matlab route by widdma on Friday March 17, 2017 @09:26AM (#13893734)
I'd second the PGFPlots recommendation. Easy to create plots by hand or you can use matlab2tikz (mentioned but dismissed in the article) if you're coming from matlab.

I'd also second the latexmk recommendation!

Re:High quality graphics for Latex documents: The Matlab route by tjl on Friday March 17, 2017 @11:59AM (#13894986)
I love matlab2tikz. I used it for all my plots in my Ph.D. thesis (and I had a lot). I also really like latexmk.

For non-plots I love Sketch (http://sketch4latex.sourceforge.net) which is pretty great for doing diagrams with 3D objects, especially if you use the sketch-lib (https://alexdu.github.io/sketch-lib/) which provides a bunch of useful simple objects to manipulate.

Re:High quality graphics for Latex documents: The Matlab route by davrosthedalek on Friday March 17, 2017 @08:48AM (#13893531)
I have yet to see a solution that beats gnuplot+tikz+LaTex in image quality. It's also trivial to script and include in a makefile. If you drive it to extremes, this is also the only solution I know of that can do proper references inside the figure key, for example a citation with bibtex. (But beware: this is too much for most publishers)
Re:High quality graphics for Latex documents: The Matlab route by MJSplot_author on Friday March 17, 2017 @10:38AM (#13894277)
There is another solution for having citations and references in figures: use Inkscape as suggested in the OP. In particular the save to pdf+latex feature. Any text elements in the figure are generated using latex. This means the correct font and the ability to write any latex you want as text. I still like hand editing figures to add complex annotations so I like being able to use Inkscape's GUI.
Re:High quality graphics for Latex documents: The Matlab route by gjulianm on Friday March 17, 2017 @09:28AM (#13893755)
Good thing is that you don't even need a Makefile. If you use latexmk it can automatically run gnuplot [1]. It's very useful if you are in "continuous-preview" mode (aka automatic builds when you change the source of the document).

http://tex.stackexchange.com/questions/106512/gnuplot-in-lat...

Re:High quality graphics for Latex documents: The Matlab route by danieldk on Friday March 17, 2017 @10:55AM (#13894394)
org-mode is also worth looking into. You can execute code fragments and embed the results using Babel[1]. Makes it simple to use the output of e.g. gnuplot or matplotlib.

I am relatively new to org-mode (via Spacemacs). But I really like it, you can use it as a quick notebook to jot down things, run code, and export the result as PDF per LaTeX.

[1] http://orgmode.org/worg/org-contrib/babel/

Re:High quality graphics for Latex documents: The Matlab route by filmor on Friday March 17, 2017 @09:59AM (#13894003)
You don't even need that, if you allow shell-escapes you can run gnuplot directly from your latex call.
Re:High quality graphics for Latex documents: The Matlab route by davrosthedalek on Friday March 17, 2017 @09:50AM (#13893918)
I was aware of latexmk, but I didn't know it can run gnuplot too. That's great! Thanks!
Re:High quality graphics for Latex documents: The Matlab route by leephillips on Friday March 17, 2017 @08:54AM (#13893564)
That is extreme - but a nice example of the implications of tight LaTeX integration!
Re:High quality graphics for Latex documents: The Matlab route by Y_Y on Friday March 17, 2017 @09:01AM (#13893596)
Gnuplot is something i categorise with Fortran and hand writing latex as "I use use it because my advisor used it, and he used it because his advisor used it...". I understand that they were once the best tool for the job and they still work, but better alternatives have emerged since, e.g. matplotlib, C++/numpy and LyX respectively. I know this is a subjective matter but i feel it's a shame that a lot of scientist don't shop around and hence end up stuck with the "classical" option.
Re:High quality graphics for Latex documents: The Matlab route by chestervonwinch on Friday March 17, 2017 @10:49AM (#13894347)
Have you used Fortran? Have you tried f2py, which converts Fortran modules into NumPy compatible Python modules? I would rather use Fortran over C++ in a heartbeat for scientific computing. For what it's worth, I thought for years that Fortran was an old crusty language, not worthy of my time, choosing to use C++ instead, and I regret not picking it up sooner.
Re:High quality graphics for Latex documents: The Matlab route by semi-extrinsic on Friday March 17, 2017 @01:06PM (#13895718)
In modern Fortran, there is only really one big headache (coming from e.g. Python), and that's how hard string processing is, and how there are no generic lists. E.g. something as simple as cpnverting an integer to a string (or vice versa) actually uses I/O and writes/reads from the int to the string. (I have written Fortran code that outputs data both in JSON, CSV, proprietary binary formats and as XML at various points in time. It's not generally pleasant.)

If a hypothetical Fortran 201x added Python-esque generic lists and list/array comprehensions that played well with strings, and promoted strings to a "first class" type, I'd have a lot less reason for pulling in Python for scientific applications not involving web/graphics.

Re:High quality graphics for Latex documents: The Matlab route by Y_Y on Friday March 17, 2017 @11:02AM (#13894448)
I have used Fortran in a few instances where I was compelled to. I never gave it much of a chance because I didn't like using it, and what's more it isn't nearly as popular as C/Python/Matlab etc. for modern stuff. If popularity (and hence code sharing) wasn't important I'd be using languages I like, like Haskell and Scheme.

All the same your comment makes me think I may have dismissed it too quickly so I'm going to give it another try for my next toy project (even if they index arrays from 1). Thank you.

Re:High quality graphics for Latex documents: The Matlab route by chestervonwinch on Friday March 17, 2017 @11:13AM (#13894538)
> even if they index arrays from 1

They don't have to! You can set the array index bounds to whatever you want. For example,

    real(8) A(0:n-1)
    real(8) w(-p:q)
are both valid declarations and would be indexed by i=0,n-1 and i=-p,q respectively. If you're using gfortran compile with the "-fbounds-check" flag to save a lot of headaches!
Re:High quality graphics for Latex documents: The Matlab route by leephillips on Friday March 17, 2017 @11:11AM (#13894528)
You can index arrays in Fortran any way you want to.

Fortran is popular among people in many disciplines doing large-scale scientific computing. I was surprised to learn a few years ago that C++ had become popular in the high energy physics community; the emphasis there is on crunching vast amounts of data from experiments.

Re:High quality graphics for Latex documents: The Matlab route by davrosthedalek on Friday March 17, 2017 @09:18AM (#13893676)
Let's put it this way: I wrote my diploma thesis in LyX, but went back to emacs+latex for my PhD. I did not regret it. Matplotlib is close, but I get results with gnuplot quicker.

My students all started out using root/matlab/whatever for plots. Except for the matlab guy, sooner or later, they all switched to gnuplot. Not forced by me.

Re:High quality graphics for Latex documents: The Matlab route by Y_Y on Friday March 17, 2017 @11:07AM (#13894499)
So you shopped around and stuck with the thing you like. That's great and nobody could argue with it. In my own department grad students and even wizened old professors are moving away from gnuplot and matlab to matplotlib, but I bet that having "experts" around is a more important factor than anything else.
Re:High quality graphics for Latex documents: The Matlab route by apathy on Friday March 17, 2017 @11:33AM (#13894737)
Why do you quote the word experts?

It doesn't appear that the objective merits of the tools under discussion yield a single best answer. For example, if you look through various implementations of assorted somewhat-esoteric algorithms & formulae, I have found that the FORTRAN implementations are usually cleanest. Not because the language is cleaner or anything like that, but because the most experienced people in the field didn't see the point of bowing to language fashion.

If fashion were the deciding point I suppose we'd all be compelled to use JavaScript, so, yeah. I'd rather not reimplement something that already works right, least of all when it's a fiddle problem and I've got deadlines to hit.

Re:High quality graphics for Latex documents: The Matlab route by Y_Y on Friday March 17, 2017 @01:00PM (#13895649)
I quoted it because, for example, within a small group, I would be the go-to person for "I need software that does X" or "I hate Y, what can I use instead?". I'm by no means an expert in, say, matplotlib, but I have local influence by means of my relative, perceived expertise.

You make a great point. The only thing that I'd add is that a lot of the Fortran code that I'd rely on (large venerable linear algebra and ODE packages) were written a long time ago, when it would have been somewhat less unfashionable.

Re:High quality graphics for Latex documents: The Matlab route by sn41 on Friday March 17, 2017 @09:04AM (#13893609)
Strange. I feel going in the opposite direction. Removing as many fancy latex packages from my documents as possible, because I am worried that my files can't be compiled 10-15 years from now.

I am a tex/latex survivalist :)

Re:High quality graphics for Latex documents: The Matlab route by davrosthedalek on Friday March 17, 2017 @01:15PM (#13895814)
The good thing about latex is that it's pure text. While the ability for nice output might be lost, generally, the intent and content of the document is still extractable.
Re:High quality graphics for Latex documents: The Matlab route by leephillips on Friday March 17, 2017 @09:07AM (#13893619)
I "shopped around" and tried all of these things, and more. I returned to LaTeX and gnuplot because they are better. I'd certainly rather use modern array Fortran than C++.
Re:High quality graphics for Latex documents: The Matlab route by radarsat1 on Friday March 17, 2017 @07:46AM (#13893221)
I've historically just used matplotlib and it's TeX-based text renderer for labels. Output PDF, includegraphics in a latex document. Works fine, text looks great. http://matplotlib.org/users/usetex.html
Re:High quality graphics for Latex documents: The Matlab route by jacobolus on Friday March 17, 2017 @07:35AM (#13893165)
> But your nice professional looking documents can be ruined because you insert the wrong type of figures.

Example A of the wrong type of figure for any possible context: 3-dimensional pie charts.

Re:High quality graphics for Latex documents: The Matlab route by lorenzhs on Friday March 17, 2017 @08:22AM (#13893388)
Most 3D plots are terrible because there's an inherent loss of information when flattened onto a 2D screen or piece of paper. Not only that, but you can't read off absolute values from a 3D chart without every point being labelled. They're also great if you want to mislead (e.g. by rotating them).

Most pie charts are terrible as well, it's very hard to compare the sizes of slices. There's a good piece on pie charts at http://www.businessinsider.com/pie-charts-are-the-worst-2013... with a quote from Edward Tufte: "Pie chart users deserve same suspicion+skepticism as those who mix up its/it's, there/their.To compare,use little table, sentence, not pies."

The combination, especially when used for a publication, is just a disaster.

Re:High quality graphics for Latex documents: The Matlab route by Tarq0n on Friday March 17, 2017 @09:25AM (#13893723)
If your audience like/expect/demand pie charts I find donut charts to be a nice alternative. They do essentially the same thing but prevent people from trying to interpret the area of wedges.

http://www.datavizcatalogue.com/methods/donut_chart.html

Re:High quality graphics for Latex documents: The Matlab route by lallysingh on Friday March 17, 2017 @08:35AM (#13893445)
And the fact that the 3rd dimension adds no information and instead adds perspective distortion.
Re:High quality graphics for Latex documents: The Matlab route by oriettaxx on Friday March 17, 2017 @08:26AM (#13893409)
Darrell Huff, in his "How to Lie With Statistics" says 3-d charts should never be used, since you can easily lie with them (by rotating it, e.g,)
Re:High quality graphics for Latex documents: The Matlab route by JohnHammersley on Friday March 17, 2017 @08:02AM (#13893288)
Yes, that is a good point -- it does include the percentages at least.
Re:High quality graphics for Latex documents: The Matlab route by stargazer-3 on Friday March 17, 2017 @09:40AM (#13893833)
Not necessarily. For instance, some academic journals are on their way to allow interactive 3d plots in the pdf files [1]

[1] http://journals.plos.org/plosone/article?id=10.1371/journal....

Re:High quality graphics for Latex documents: The Matlab route by widdma on Friday March 17, 2017 @09:44AM (#13893862)
3D plots can useful when the data is intrinsically 3D. But forcing a 3D plot on 2D data, like a pie chart, makes it hard for a viewer to develop an intuition for the data.
Re:High quality graphics for Latex documents: The Matlab route by stargazer-3 on Friday March 17, 2017 @09:56AM (#13893974)
Fair point, I overlooked the "pie" part of the chart argument. My comment was originally intended to go as a reply to oriettaxx's post.
Re:High quality graphics for Latex documents: The Matlab route by leni536 on Friday March 17, 2017 @11:45AM (#13894833)
AFAIK the only viewer that supports interactive 3D in pdf is Adobe Reader. At this point should we stick to the pdf format? Obviously interactive 3D is not meant for printing anyway. Some open access journals publish in html format too, 3D plots can work there better.
Re:High quality graphics for Latex documents: The Matlab route by detaro on Friday March 17, 2017 @09:41AM (#13893844)
Which they hopefully won't allow to be used for 3d pie charts, but visualizations where being 3D is actually useful.
Re:High quality graphics for Latex documents: The Matlab route by lottin on Friday March 17, 2017 @11:20AM (#13894607)
R can output Tikz code. Probably the best option for statistics-related work.

http://www.texample.net/tikz/examples/tikzdevice-demo/

Re:High quality graphics for Latex documents: The Matlab route by jtraffic on Friday March 17, 2017 @12:01PM (#13895017)
I second this. I read a paper yesterday and the figures produced by R clashed visually with the typesetting style. The Tikz ones are so, so, nice.
Re:High quality graphics for Latex documents: The Matlab route by djoshea on Friday March 17, 2017 @02:21PM (#13896533)
If you're not specifically looking for Computer Modern fonts in your figures but just want vector graphic WYSIWYG exports with your pick of font (beyond what Matlab renders natively), my Matlab figure export tool works well:

https://github.com/djoshea/matlab-save-figure

Re:High quality graphics for Latex documents: The Matlab route by widdma on Friday March 17, 2017 @09:22AM (#13893695)
I found matlabl2tikz to be superior to plot2latex. I did my honours thesis with plot2LaTeX+inkscape and my PhD one with a matlab2tikz, so I've had a fair experience with both.

I have created some high quality, complex plots out through matlabl2tikz with no problem. I haven't had the issues the author notes and I'd suggest they file a bug report. The m2t community is active and friendly.

The other bonus of m2t is you can edit the files in PGFplots, which is a powerful and complete language/library. For my use case, it was important that my plots be repeatable, so manually doing it with Inkscape would be tedious. Having easily editable source code allowed me to write scripts to filter the output to what I needed.

The one problem I did find is that pgfplots can be quite slow. This isn't m2t's fault though and can be overcome with TikZ's cache system.

Disclosure: I wrote the path simplification in matlab2tikz, but nothing else.

Re:High quality graphics for Latex documents: The Matlab route by amelius on Friday March 17, 2017 @08:23AM (#13893392)
Maybe it's just me, but why can't Matlab just use the Latex fonts in an EPS, and output that EPS as a single file? That sounds like a more robust and less convoluted solution.
Re:High quality graphics for Latex documents: The Matlab route by JorgeGT on Friday March 17, 2017 @08:52AM (#13893551)
I think that the goal of the poster is not just the font, is to be able to modify the size/font/color/style when compiling the document (say that you realize you want bold labels, or sans-serif instead of serif when you have a lot of figures already generated).
Re:High quality graphics for Latex documents: The Matlab route by amelius on Friday March 17, 2017 @09:03AM (#13893606)
In that case, I'd recommend structuring your scripts such that you can easily rerun them later on (e.g. using a Makefile). That has also other advantages, such as the ability to change graph colors, axes, or even data.
Re:High quality graphics for Latex documents: The Matlab route by IanCal on Friday March 17, 2017 @09:55AM (#13893968)
I'm a big fan of being able to generate a document and know that the results are all based on the same, latest data and the same code. The more different things I have to do to generate it all from scratch the more likely there's something I'll forget when I have just fixed a problem somewhere.
Re:High quality graphics for Latex documents: The Matlab route by JorgeGT on Friday March 17, 2017 @10:55AM (#13894403)
This is what I do, really. Regarding styling I have a small styling script that I put after each graph. This small script takes the active figure (gcf) whatever it is, and changes it to my liking. So if I want to change the graph styling at a later stage I modify this small script and then re-run the main file.

But everything in MATLAB, then I just symlink the pdf figures to the manuscript folder, so with an F5 in MATLAB and a build in Sublime I have the manuscript updated.

Re:High quality graphics for Latex documents: The Matlab route by tjl on Saturday March 18, 2017 @02:46AM (#13900230)
My only problem with doing everything in Matlab (which I used to do) and exporting the PDF is that you can't really match the fonts easily to the main document. I picked a set of fonts (math and normal) for my Ph.D. thesis and I wanted the fonts in the figures to match those in the main body. Using matlab2tikz did that for me.

You could probably do the same thing but do the export of the tikz file instead of the PDF. That's basically what I do.

Re:High quality graphics for Latex documents: The Matlab route by Bedon292 on Friday March 17, 2017 @10:49AM (#13894343)
I have taken to using PowerPoint to create the actual charts. Edit them and make them look pretty. Then export as EMF, convert to EPS (https://www.cs.bu.edu/~reyzin/pictips.html) and use the EPS in the Tex document.

Its a very manual process though, but I think the graphics that come out of it seem to be nicer than Matplotlib, and Matlab can do. Am I crazy, or should I really consider something like this?

Re:High quality graphics for Latex documents: The Matlab route by lottin on Friday March 17, 2017 @11:10AM (#13894522)
Personally I prefer to generate all plots (and ideally tables as well) programatically. It's more reliable and efficient. Imagine that at some point you decide to include more data in the analysis (or remove erroneous data) you don't want to re-do all the work again.
Re:High quality graphics for Latex documents: The Matlab route by taliesinb on Friday March 17, 2017 @10:25AM (#13894180)
In Mathematica, Export[expr,"PDF"], Export[expr, "SVG"], and Export[expr,"LaTeX"] for math expressions.
Re:High quality graphics for Latex documents: The Matlab route by taliesinb on Friday March 17, 2017 @03:39PM (#13897277)
That should be ExportString[expr,"PDF"], sorry! Or Export["file.pdf", expr].
Re:High quality graphics for Latex documents: The Matlab route by dallamaneni on Friday March 17, 2017 @02:13PM (#13896445)
I was thinking exactly the same. This post just reminds me how easy it is with Mathematica
Re:High quality graphics for Latex documents: The Matlab route by tnecniv on Friday March 17, 2017 @03:05PM (#13896956)
Mathematica is a really awesome tool.
Re:High quality graphics for Latex documents: The Matlab route by thisrod on Friday March 17, 2017 @07:05PM (#13898741)
I started working on a Matlab command to export plotted data as Metapost paths, and to generate a script that draws the plot. The idea being that you would edit the script to get the style you wanted.

The proof of concept worked well for line and contour plots, but my thesis got in the way of completing this.

Re:High quality graphics for Latex documents: The Matlab route by moultano on Friday March 17, 2017 @10:09AM (#13894070)
Does anyone know of an equivalent solution for R/ggplot? I feel sad labelling my plots with R's fonts and equation formatting, but haven't found an alternative.
Re:High quality graphics for Latex documents: The Matlab route by andrewla on Friday March 17, 2017 @10:26AM (#13894188)
tikzDevice [1] defines a device in tikz terms, which I've used for vanilla R plots, and should work for ggplot, but I'm not positive.

Actually, a quick search yielded [2], so it appears that ggplot2 is supported as well. And apparently supported in one of the knitr examples [3] (if you use knitr, which I highly recommend).

[1] https://cran.r-project.org/web/packages/tikzDevice/index.htm...

[2] http://iltabiai.github.io/tips/latex/2015/09/15/latex-tikzde...

[3] https://yihui.name/knitr/demo/graphics/

Re:High quality graphics for Latex documents: The Matlab route by partycoder on Friday March 17, 2017 @10:35AM (#13894252)
I wonder if there is a similar guide for Scilab.