All Projects → nilsleiffischer → texfig

nilsleiffischer / texfig

Licence: MIT license
Utility to generate PGF vector files from Python's Matplotlib plots to use in LaTeX documents.

Programming Languages

python
139335 projects - #7 most used programming language
TeX
3793 projects

Projects that are alternatives of or similar to texfig

Matplotlib Venn
Area-weighted venn-diagrams for Python/matplotlib
Stars: ✭ 260 (+348.28%)
Mutual labels:  matplotlib, plotting
Chartpy
Easy to use Python API wrapper to plot charts with matplotlib, plotly, bokeh and more
Stars: ✭ 426 (+634.48%)
Mutual labels:  matplotlib, plotting
Brokenaxes
Create matplotlib plots with broken axes
Stars: ✭ 266 (+358.62%)
Mutual labels:  matplotlib, plotting
cplot
🌈 Plot complex functions
Stars: ✭ 75 (+29.31%)
Mutual labels:  matplotlib, plotting
Cmasher
Scientific colormaps for making accessible, informative and 'cmashing' plots
Stars: ✭ 149 (+156.9%)
Mutual labels:  matplotlib, plotting
microfilm
Creating figures and animations for multi-channel images with a focus on microscopy.
Stars: ✭ 22 (-62.07%)
Mutual labels:  matplotlib, plotting
Pyplot.jl
Plotting for Julia based on matplotlib.pyplot
Stars: ✭ 347 (+498.28%)
Mutual labels:  matplotlib, plotting
expyplot
Matplotlib for Elixir
Stars: ✭ 27 (-53.45%)
Mutual labels:  matplotlib, plotting
Pandoc Plot
Render and include figures in Pandoc documents using your plotting toolkit of choice
Stars: ✭ 75 (+29.31%)
Mutual labels:  matplotlib, plotting
Mplcyberpunk
"Cyberpunk style" for matplotlib plots
Stars: ✭ 762 (+1213.79%)
Mutual labels:  matplotlib, plotting
geneview
Genomics data visualization in Python by using matplotlib.
Stars: ✭ 38 (-34.48%)
Mutual labels:  matplotlib, plotting
2021-bordeaux-dataviz
Scientific Visualization Crash Course (Python & Matplotlib)
Stars: ✭ 20 (-65.52%)
Mutual labels:  matplotlib, plotting
SciPlot-PyQt
A Matplotlib-wrapped user-interface for creating and editing publication-ready images and plots
Stars: ✭ 32 (-44.83%)
Mutual labels:  matplotlib, plotting
Matplotlib
matplotlib: plotting with Python
Stars: ✭ 14,738 (+25310.34%)
Mutual labels:  matplotlib, plotting
joypy
Joyplots in Python with matplotlib & pandas 📈
Stars: ✭ 418 (+620.69%)
Mutual labels:  matplotlib, plotting
Joypy
Joyplots in Python with matplotlib & pandas 📈
Stars: ✭ 322 (+455.17%)
Mutual labels:  matplotlib, plotting
dufte
📈 Minimalistic Matplotlib style
Stars: ✭ 196 (+237.93%)
Mutual labels:  matplotlib, plotting
planetMagFields
Routines to plot magnetic fields of planets in our solar system
Stars: ✭ 27 (-53.45%)
Mutual labels:  matplotlib, plotting
Adjusttext
A small library for automatically adjustment of text position in matplotlib plots to minimize overlaps.
Stars: ✭ 731 (+1160.34%)
Mutual labels:  matplotlib, plotting
Scientific Visualization Book
An open access book on scientific visualization using python and matplotlib
Stars: ✭ 6,336 (+10824.14%)
Mutual labels:  matplotlib, plotting

TexFig

DOI

Python's Matplotlib can save plots as PGF vector files, with text containing LaTeX code and all. LaTeX can render PGF files. Sounds like a perfect match, doesn't it? (It does. See my bachelor thesis for example plots.)

Example for a PGF plot in LaTeX

Why PGF?

  • It's a vector format. No blurry pixel graphics anymore!
  • Any text in your plots will be typeset with your document's native font and style.
  • You can use your custom LaTeX \newcommand macros in your plots after defining a dummy implementation for them in Python. They will be typeset correctly in your document.

Usage

  1. Download the repository and run

    python example.py

    to test your Python and LaTeX setup.

  2. Copy the texfig.py file next to your Python script. It is just some simple setup and utility code for matplotlib to get you started, so feel free to edit any configurations within.

  3. Use texfig to generate PGF plots:

    # import texfig first to configure Matplotlib's backend
    import texfig  # assuming texfig.py and an __init__.py is in the directory
    # then, import PyPlot as usual
    import matplotlib.pyplot as plt
    
    # obtain a nicely configured figure from texfig
    fig = texfig.figure()
    # plot as usual
    plt.plot(range(10))
    # save your plot as both a PGF file (for inclusion in LaTeX) and a PDF file (for preview only)
    texfig.savefig("example_plot")

    You can adjust the settings in texfig.py to your liking. In particular, you may want to set the default_width to your LaTeX \textwidth (in inches). In the pgf.preamble list you can also define any macros that you have implemented in your LaTeX document and that you wish to use in your plots. Don't worry about implementing them correctly here, since they are rendered by your LaTeX document later anyway.

    Make sure that no call to change matplotlib backends precedes the import texfig statement, and do not change backends afterwards either. In particular, refrain from using %matplotlib inline configurations in Jupyter Notebooks.

  4. Now \usepackage{pgf} and \input the PGF file in your LaTeX document:

    % in the preamble
    \usepackage{pgf}
    % somewhere in your document
    \input{example_plot.pgf}
  5. Admire the beauty of LaTeX vector plots.

Hint: If your PGF plots end up slowing down your LaTeX compile times too much, consider omitting the PGF rendering in draft mode like so:

% in the preamble
\usepackage{ifdraft}
\newcommand{\plot}[1]{\ifdraft{\includegraphics{#1.pdf}}{\input{#1.pgf}}}
% somewhere in your document
\plot{example_plot}

Now when you give your \documentclass the option draft, a placeholder of the correct size is rendered instead of the PGF plot. Note that for this to work you need to keep the preview PDF generated by texfig.savefig in addition to the corresponding PGF file in the same directory.

Contact

TexFig was created and is maintained by Nils Leif Fischer.

License

TexFig is released under the MIT license. See LICENSE.md for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].