{"id":18358383,"url":"https://github.com/wiseodd/pub-ready-plots","last_synced_at":"2025-04-06T22:06:41.312Z","repository":{"id":243144294,"uuid":"811578863","full_name":"wiseodd/pub-ready-plots","owner":"wiseodd","description":"Agustinus' very opiniated publication-ready plotting library","archived":false,"fork":false,"pushed_at":"2025-01-31T18:14:11.000Z","size":637,"stargazers_count":62,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T14:49:09.547Z","etag":null,"topics":[],"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/wiseodd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-06T21:55:47.000Z","updated_at":"2025-03-02T10:39:56.000Z","dependencies_parsed_at":"2025-01-14T17:09:26.486Z","dependency_job_id":"466ef3d6-879f-4f6e-adff-20faa353939e","html_url":"https://github.com/wiseodd/pub-ready-plots","commit_stats":null,"previous_names":["wiseodd/pub-ready-plots"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiseodd%2Fpub-ready-plots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiseodd%2Fpub-ready-plots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiseodd%2Fpub-ready-plots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wiseodd%2Fpub-ready-plots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wiseodd","download_url":"https://codeload.github.com/wiseodd/pub-ready-plots/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557767,"owners_count":20958047,"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":[],"created_at":"2024-11-05T22:17:41.696Z","updated_at":"2025-04-06T22:06:41.289Z","avatar_url":"https://github.com/wiseodd.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Agustinus' _Very_ Opiniated Publication-Ready Plotting Library\n\n\u003cdiv align=\"center\"\u003e\n\n[![PyPI version](https://badge.fury.io/py/pub-ready-plots.svg)](https://badge.fury.io/py/pub-ready-plots)\n[![codecov](https://codecov.io/github/wiseodd/pub-ready-plots/graph/badge.svg?token=N2I020J0RR)](https://codecov.io/github/wiseodd/pub-ready-plots)\n![pytest](https://github.com/wiseodd/pub-ready-plots/actions/workflows/pytest.yml/badge.svg)\n![mypy-lint](https://github.com/wiseodd/pub-ready-plots/actions/workflows/lint-mypy.yml/badge.svg)\n![ruff-lint](https://github.com/wiseodd/pub-ready-plots/actions/workflows/lint-ruff.yml/badge.svg)\n![ruff-format](https://github.com/wiseodd/pub-ready-plots/actions/workflows/format-ruff.yml/badge.svg)\n\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\nI love TikZ (btw). I love [tikzplotlib](https://github.com/nschloe/tikzplotlib). I've been an\nadvocate for the latter ([proof](https://agustinus.kristia.de/blog/plotting/)). However, tikzplotlib is [as good as dead](https://github.com/nschloe/tikzplotlib/commits/main/). I need to move on.\n\n\u003e [!IMPORTANT]\n\u003e Here's what I use now for all my publication needs. This library is designed to be\n\u003e _*very*_ opiniated. Beauty is in the eye of the beholder. Also, it is _very_ simple,\n\u003e just a single file and that's it.\n\n\u003e [!NOTE]\n\u003e Of course I still use TikZ whenever possible (e.g. Fig. 1 in a paper, diagrams, etc.)\n\n## Examples\n\n**Left:** ICML (letter size), single-column layout. **Right:** A0 landscape poster, 3-column layout.\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"imgs/example_paper.png\" width=\"40%\"\u003e \u0026nbsp \u0026nbsp \u0026nbsp \u0026nbsp \u003cimg src=\"imgs/example_poster.png\" width=\"43.7%\"\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n```diff\nimport pub_ready_plots as prp\n\n...\n\nprp.get_context(\n-   layout=prp.Layout.ICML,\n+   layout=prp.Layout.POSTER_LANDSCAPE,\n\n...\n```\n\n## Installation\n\nStill with me? Still want to use this library? Here's how:\n\n```bash\npip install --upgrade pub-ready-plots\n```\n\n## Quick usage\n\nWrap you current plotting script with the following `with` statement.\nBy default, this will create a full-width, `0.15\\textheight` figure that conforms\nto the specified template.\n\nBy doing this, your figure is guaranteed to have the correct scaling, dimensions,\nfont faces, and font sizes. All in all, this makes your figure \"blends\" with\nthe target venue's main template---your paper overall will look more professional!\n\n```python\nimport pub_ready_plots as prp\n\nwith prp.get_context(layout=prp.Layout.ICLR) as (fig, axs):\n    # Do whatever you want with `fig` and `axs`, e.g.:\n    x = np.linspace(-1, 1)\n    axs.plot(x, np.cos(x))\n\n    # Once your done, save it, but do NOT set `tight_layout=True`!\n    fig.savefig(\"filename.pdf\")\n```\n\nThen in your LaTeX file, include the plot as follows:\n\n```tex\n\\includegraphics[width=\\linewidth]{filename.pdf}\n```\n\nThe argument `width=\\linewidth` is **crucial**! Also, do not specify the `height`\noption! Otherwise, your plot is distorted. (All measurements have been done in\n`pub-ready-plots`.)\n\nIf you set the `width_frac` argument when you call `prp.get_context()`, you need\nto put the same scaling factor in your LaTeX code. E.g., if you call\n`prp.get_context(..., width_frac=0.5, ...)`, then you include it via\n`\\includegraphics[width=0.5\\linewidth]{...}`.\n\n\u003e [!WARNING]\n\u003e If you want to have multiple subplots in a single figure in your paper,\n\u003e **DO NOT** create multiple pdf files! Instead, follow\n\u003e [this example](#creating-subplots), while keeping\n\u003e `\\includegraphics[width=\\linewidth]` without a scaling factor.\n\nThat's it! But you should use TikZ more.\nAnyway, see the full, runnable example in [`examples/simple_plot.py`](https://github.com/wiseodd/pub-ready-plots/blob/master/examples/simple_plot.py)\nSee [here](#all-available-options) for available options for `get_context()`!\n\n\u003e [!TIP]\n\u003e I recommend using this library in conjunction with\n\u003e [pypalettes](https://github.com/JosephBARBIERDARNAL/pypalettes)\n\u003e to avoid the generic blue-orange Matplotlib colors.\n\u003e Distinguish your plots from others!\n\n## Advanced usages\n\n### Creating a figure with multiple subplots\n\nTo create a figure with multiple subplots do the following.\nNote that in your LaTeX doc, you still include the pdf via\n`\\includegraphics[width=\\linewidth]`, without any scaling factor.\n\n```python\nwith prp.get_context(\n    layout=prp.Layout.NEURIPS,\n    width_frac=1,\n    height_frac=0.15,\n    nrows=1,\n    ncols=2,\n    sharey=True,\n) as (fig, axs):\n    # As an example, we plot sine and cosine functions\n    x = np.linspace(-1, 1, 100)\n\n    axs[0].plot(x, np.sin(x))\n    axs[0].set_title(\"Sine\")\n    axs[0].set_xlabel(r\"$x$\")\n    axs[0].set_ylabel(r\"$\\mathrm{sin}(x)$\")\n\n    axs[1].plot(x, np.cos(x))\n    axs[1].plot(x, 2 * np.cos(x))\n    axs[1].set_title(\"Cosine\")\n    axs[1].set_xlabel(r\"$x$\")\n    axs[1].set_ylabel(r\"$\\mathrm{cos}(x)$\")\n\n    fig.savefig(\"subplots.pdf\")\n```\n\n### Creating plots for `\\wrapfigure`\n\nSay we want to have an inline figure of size `0.4\\textwidth` and\nheight `0.15\\textheight` in our NeurIPS paper.\nThen all we have to do is the following:\n\n```python\nimport pub_ready_plots as prp\n\nwith prp.get_context(\n    layout=prp.Layout.NEURIPS, width_frac=0.4, height_frac=0.15,\n) as (fig, axs):\n    # Your plot here!\n    ...\n    fig.savefig(\"mywrapfigure.pdf\")\n```\n\nIn our LaTeX doc, we can then use the `wrapfig` package and do the following:\n\n```tex\nSome paragraph.\n\n\\begin{wrapfigure}[11]{r}{0.4\\textwidth}\n  \\centering\n  \\includegraphics[width=\\linewidth]{mywrapfigure.pdf}\n  ...\n\\end{wrapfigure}\n\nSome other paragraph.\n```\n\n\u003e [!IMPORTANT]\n\u003e In the `\\begin{wrapfigure}` statement, specify the correct figure size\n\u003e (in our case, `0.4\\textwidth`). Then, in the `\\includegraphics` statement,\n\u003e **_always_** specify `width=\\linewidth` _without_ specifying the height.\n\n### Usage with Seaborn\n\nThis library is compatible with Seaborn, see [example](https://github.com/wiseodd/pub-ready-plots/blob/master/examples/with_seaborn.py).\nThe most important thing to remember is to always pass the axis returned by\n`prp.get_context()` to Seaborn's plotting functions. Example:\n\n```python\nimport seaborn as sns\nimport pub_ready_plots as prp\n\nwith prp.get_context(layout=prp.Layout.SLIDES_196) as (fig, ax):\n    sns.histplot(\n        data=sns.load_dataset(\"planets\"), x=\"distance\", log_scale=True\n        ax=ax  # !! IMPORTANT !!\n    )\n```\n\n### Poster, slides fonts too bold?\n\nThe default font is Avenir Next Condensed.\nIn MacOS, to font format is `.ttc` and Matplotlib has issue with it.\nSo, please install the more standard `.ttf` version.\n\nYou can also use different fonts:\n\n```python\nimport pub_ready_plots as prp\n\nwith prp.get_context(\n    ...\n    override_rc_params={\"font.sans-serif\": \"YOUR_FONT_NAME\"},\n    ...\n) as (fig, axs):\n    ...\n```\n\n### All available options\n\n```python\nimport pub_ready_plots as prp\n\nwith prp.get_context(\n    layout=prp.Layout.ICML,  # check `Layout` for all available layouts\n    width_frac=1,  # multiplier for `\\linewidth`\n    height_frac=0.15,  # multiplier for `\\textheight`\n    single_col=False,  # only works for the ICML, UAI, AISTATS layouts\n    nrows=1,  # depending on your subplots, default = 1\n    ncols=2,  # depending on your subplots, default = 1\n    override_rc_params={\"lines.linewidth\": 4.123},  # Overriding rcParams\n    sharey=True,  # Additional keyword args for `plt.subplots`\n) as (fig, axs):\n    ...\n\n    fig.savefig(\"filename.pdf\")\n```\n\n### Using your own styles\n\nTwo options:\n\n1. Use this library and update the resulting `rc_params` dict with your styles.\n   - See [`examples/advanced_usage.py`](https://github.com/wiseodd/pub-ready-plots/blob/master/examples/advanced_usage.py)\n2. Fork this repo and modify things as you wish.\n\n## Other libraries\n\nCheck out [tueplots](https://github.com/pnkraemer/tueplots) if you want a more complex\nlibrary. My library is designed to achieve what **_I_** want in **_my_** papers and\nposters, with as little code as possible. Because of this, it is very forkable and hackable.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiseodd%2Fpub-ready-plots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwiseodd%2Fpub-ready-plots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwiseodd%2Fpub-ready-plots/lists"}