{"id":22478182,"url":"https://github.com/nilsvu/texfig","last_synced_at":"2025-08-02T13:31:37.097Z","repository":{"id":77875002,"uuid":"53438825","full_name":"nilsvu/texfig","owner":"nilsvu","description":"Utility to generate PGF vector files from Python's Matplotlib plots to use in LaTeX documents.","archived":false,"fork":false,"pushed_at":"2023-03-15T17:17:53.000Z","size":491,"stargazers_count":66,"open_issues_count":1,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-10-20T22:04:41.568Z","etag":null,"topics":["latex","matplotlib","pgf","plotting","python","vector-graphics"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nilsvu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-03-08T19:23:30.000Z","updated_at":"2023-10-20T22:04:41.917Z","dependencies_parsed_at":"2023-04-22T01:37:13.573Z","dependency_job_id":null,"html_url":"https://github.com/nilsvu/texfig","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilsvu%2Ftexfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilsvu%2Ftexfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilsvu%2Ftexfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilsvu%2Ftexfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nilsvu","download_url":"https://codeload.github.com/nilsvu/texfig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228475977,"owners_count":17926134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["latex","matplotlib","pgf","plotting","python","vector-graphics"],"created_at":"2024-12-06T14:13:36.229Z","updated_at":"2024-12-06T14:13:36.814Z","avatar_url":"https://github.com/nilsvu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TexFig\n\n[![DOI](https://zenodo.org/badge/53438825.svg)](https://zenodo.org/badge/latestdoi/53438825)\n\nPython's [Matplotlib](http://matplotlib.org) can save plots as [PGF vector files](https://en.wikipedia.org/wiki/PGF/TikZ), 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](https://github.com/knly/bsc-thesis/blob/master/dist/bsc_digital.pdf) for example plots.)\n\n![Example for a PGF plot in LaTeX](example.png)\n\n\n## Why PGF?\n\n- It's a vector format. No blurry pixel graphics anymore!\n- Any text in your plots will be typeset with your document's native font and style.\n- 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.\n\n\n## Usage\n\n1. [Download](https://github.com/nilsleiffischer/texfig/archive/master.zip) the repository and run\n\n \t```bash\n\tpython example.py\n\t```\n\n\tto test your Python and LaTeX setup.\n2. 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.\n3. Use `texfig` to generate PGF plots:\n\n\t```python\n\t# import texfig first to configure Matplotlib's backend\n\timport texfig  # assuming texfig.py and an __init__.py is in the directory\n\t# then, import PyPlot as usual\n\timport matplotlib.pyplot as plt\n\n\t# obtain a nicely configured figure from texfig\n\tfig = texfig.figure()\n\t# plot as usual\n\tplt.plot(range(10))\n\t# save your plot as both a PGF file (for inclusion in LaTeX) and a PDF file (for preview only)\n\ttexfig.savefig(\"example_plot\")\n\t```\n\n\tYou 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.\n\n\t\u003e 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.\n\n4. Now `\\usepackage{pgf}` and `\\input` the PGF file in your LaTeX document:\n\n\t```tex\n\t% in the preamble\n\t\\usepackage{pgf}\n\t% somewhere in your document\n\t\\input{example_plot.pgf}\n\t```\n\n5. Admire the beauty of LaTeX vector plots.\n\n\u003e 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:\n\u003e\n\u003e ```tex\n\u003e % in the preamble\n\u003e \\usepackage{ifdraft}\n\u003e \\newcommand{\\plot}[1]{\\ifdraft{\\includegraphics{#1.pdf}}{\\input{#1.pgf}}}\n\u003e % somewhere in your document\n\u003e \\plot{example_plot}\n\u003e ```\n\u003e\n\u003e 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.\n\n## Contact\n\nTexFig was created and is maintained by [Nils Leif Fischer](https://nilsleiffischer.de).\n\n\n## License\n\nTexFig is released under the MIT license. See [LICENSE.md](LICENSE.md) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnilsvu%2Ftexfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnilsvu%2Ftexfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnilsvu%2Ftexfig/lists"}