Tag Info

Hot answers tagged

9

There is matplotlib2tikz, which creates a TikZ/pgfplots file that can be \input in your document. I don't know how well it works, having never used matplotlib, but I have used matlab2tikz from the same author, and that works well. Also, I do not know if matplotlib2tikz supports all the different kinds of plots that matplotlib can create – in the Matlab case ...


7

For diagrams you will get the best results when using vector graphics. Both gnuplot and matplotlib can export to vector graphics; file formats for vector graphics are e.g. eps or pdf or svg (there are many more). As you are using pdfLaTeX, you should choose pdf as output format, because it will be easy to include in your document using the graphicx ...


6

Matplotlib now includes a PGF backend as of the 1.2 release. See this GitHub issue.


5

Matplotlib apparently uses Courier as default, my LaTeX uses Computer Modern Typewriter. I found some font specification examples here. So changing the first line of my preamble to rc('font', **{'family':'serif', 'serif':['Computer Modern Roman'], 'monospace': ['Computer Modern Typewriter']}) renders the \texttt{} the ...


4

import numpy as np import matplotlib.pyplot as pl x = np.linspace(0, 10, 100) y = np.sin(x) fig = pl.figure(figsize=(8,5)) ax = pl.gca() pl.axis('off') pl.plot(x, y) pl.xlim(0,10) pl.ylim(-1,1) pl.subplots_adjust(left=0, right=1, top=1, bottom=0) pl.savefig('out.pdf') This generates a sine plot completely without margins. The resulting pdf can then be ...


4

The matplotlib PGF backend saves as raw PGF. What you probably want instead is pgfplots, which you can get using matplotlib2tikz, assuming your plots aren't too complex and all the features are supported. Sample Python script for creating figure: from pylab import * from matplotlib2tikz import save as tikz_save x = linspace(0, 10, 101) plot(x, sin(x)) ...


4

Comparison matplotlib's PGF backend Plots will be saved as PGF commands, which are lower-level and thus less suitable for manual editing. This only really matters if you aren't going to go back to Python when you need to change things. (You can also save plots directly to PDF instead.) The layout will be (more or less) what the matplotlib developers ...


3

Your problem is simply that pyplot.cm.rainbow does not return CMYK values, but RGB + alpha. An excerpt from the docstring: Returns Tuple of RGBA values if X is scalar, othewise an array of RGBA values with a shape of X.shape + (4, ). Hence, by using \definecolor{colorname}{rgb}{a,b,c} where a,b,c are the first three values from rainbow, the ...


3

This does not answer your question directly, but is perhaps a possible workaround: As I mentioned in Set fonts in matplotlib graphs equal to tex document you can perhaps export your plot with the script matplotlib2tikz. This gives you a .tex file with a TikZ/pgfplots figure that can be input in your document. This will use the same fonts as the document. ...


3

Quick answer Since the command that imports the png files inside the pgf image is pgfimage, I redefined it like this: \let\pgfimageWithoutPath\pgfimage \renewcommand{\pgfimage}[2][]{\pgfimageWithoutPath[#1]{figures/#2}} The first line copies the original pgfimage command to a temporary pgfimageWithoutPath. The second line redefines pgfimage to be the ...


3

adding amstext to the complement of packages used for matplotlib will make available the \text{...} command, which matches the surrounding text style and also uses the proper size in various parts of math expressions. amstext is incorporated in amsmath, but the latter is probably overkill in this case. coding of the questioned expression would then best be ...


2

Here's an "arrow box" macro based on LaTeX picture mode. Maybe this will work for you? \documentclass{article} \makeatletter \newdimen\ab@texttotalheight \newdimen\ab@arrowstemwidth \newdimen\ab@arrowheadwidth \newdimen\ab@arrowwidth \newdimen\ab@arrowstemheight \newdimen\ab@arrowheight \newcommand\rightarrowbox{\@arrowbox+} ...


2

For your second question: You can use matplotlib from within LaTeX using the PythonTeX package. Since PythonTeX requires a cycle of running LaTeX, running a Python script, and then running LaTeX again, it will be a little slower than using Python directly if you need to do a lot of interactive work with your plot. But you could always develop the plot ...


2

For your first question: Use Tikzedt or Qtikz/ktikz depending on windows/linux or Tikzit


1

The format of the graphic depends on the content. JPG is good for pictures, PNG was designed for content containing text. For good print you will need a solution of at least 300 dpi. Using a PDF as a container will not solve the problem of a poor graphic. So look at the format and the dots per inch of the image.



Only top voted, non community-wiki answers of a minimum length are eligible