|logo|
*********
|deploy-docs|
*texplot* is a python package to enhance *matplotlib* plots with publication-quality style.
Links
=====
* `Documentation <https://ameli.github.io/texplot>`__
* `PyPI <https://pypi.org/project/texplot/>`__
* `Anaconda <https://anaconda.org/s-ameli/texplot>`__
* `Github <https://github.com/ameli/texplot>`__
Install
=======
This package requires :math:`\LaTeX` to be installed. Ensure that the ``latex`` executable is available on your system's ``PATH``.
Install with ``pip``
--------------------
|pypi|
::
pip install texplot
Install with ``conda``
----------------------
|conda-version|
::
conda install s-ameli::texplot
Set Theme
=========
`texplot` can set theme either globally or locally:
Set Theme Globally
------------------
Call `texplot.set_theme <https://ameli.github.io/texplot/generated/texplot.set_theme.html#texplot.set_theme>`__ function to set the *texplot* theme globally in your script:
.. code-block:: python
>>> import matplotlib.pyplot as plt
>>> import texplot
>>> texplot.set_theme()
>>> # Plot an example function
>>> fig, ax = plt.subplots()
>>> texplot.examples.plot_function(ax)
>>> plt.show()
.. figure:: https://github.com/ameli/texplot/raw/main/docs/source/_static/images/plots/function.png
:align: left
:figwidth: 100%
:width: 100%
The theme set as described above will affect your entire Python script for its duration. However, you can revert to the default *matplotlib* theme at any time by calling the `texplot.reset_theme <https://ameli.github.io/texplot/generated/texplot.reset_theme.html#texplot.reset_theme>`__ function as shown below:
.. code-block:: python
>>> # Resetting to default matplotlib theme
>>> texplot.reset_theme()
>>> # Plot another example function
>>> fig2, ax2 = plt.subplots()
>>> texplot.examples.plot_function(ax2)
>>> plt.show()
.. figure:: https://github.com/ameli/texplot/raw/main/docs/source/_static/images/plots/function_no_theme.png
:align: left
:figwidth: 100%
:width: 100%
Set Theme Within a Local Scope
------------------------------
The `texplot.theme <https://ameli.github.io/texplot/generated/texplot.theme.html#texplot.theme>`__ function acts as a context manager, allowing you to apply the *texplot* theme within a specific local scope or function. The example below demonstrates setting the theme in a local scope. Outside of this scope, the default *matplotlib* theme remains unchanged.
.. code-block:: python
>>> import matplotlib.pyplot as plt
>>> import texplot
>>> with texplot.theme():
>>> fig, ax = plt.subplots()
>>> texplot.examples.plot_function(ax)
>>> plt.show()
Similarly, you can use the context manager with a function. In the example below, the *texplot* theme is applied only within the ``plot()`` function. Outside this function, the default *matplotlib* theme remains unchanged.
.. code-block:: python
>>> import matplotlib.pyplot as plt
>>> import texplot
>>> @texplot.theme()
>>> def plot():
>>> fig, ax = plt.subplots()
>>> texplot.examples.plot_function(ax)
>>> plt.show()
>>> plot()
Theme Options
=============
You can customize the theme by passing arguments to either the `texplot.set_theme <https://ameli.github.io/texplot/generated/texplot.set_theme.html#texplot.set_theme>`__ or `texplot.theme <https://ameli.github.io/texplot/generated/texplot.theme.html#texplot.theme>`__ functions. The parameters for both functions are identical and detailed in the `API reference <https://ameli.github.io/texplot/api.html>`__. The available arguments are as follows:
.. list-table::
:header-rows: 1
* - Argument
- Value
- Description
* - ``context``
- ``'paper'``, ``'notebook'`` (default), ``'talk'``, or ``'poster'``
- Adjusts font size and scales of the plot depending on the context.
* - ``style``
- See `matplotlib.style.available <https://matplotlib.org/stable/api/style_api.html#matplotlib.style.available>`__
- Sets `matplotlib style <https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html>`__
* - ``font_scale``
- float (default is ``1``)
- Scales the fonts.
* - ``use_latex``
- boolean (default is `True`)
- If `True`, the mathematical symbols are rendered with :math:`\LaTeX`.
* - ``rc``
- dictionary (default is ``{}``)
- Passes any additional `matplotlib`'s `rcParam dictionary <https://matplotlib.org/stable/users/explain/customizing.html>`__.
In the example below, we configure a dark background style, increase the font size by a factor of 1.2, and set the font family to sans-serif:
.. code-block:: python
>>> import matplotlib.pyplot as plt
>>> import texplot
>>> with texplot.theme(
... rc={'font.family': 'sans-serif'},
... style='dark_background',
... font_scale=1.2):
>>>
>>> # Plot an example diagram
>>> fig, ax = plt.subplots()
>>> texplot.examples.plot_bifurcation_diagram(ax)
>>> plt.show()
.. figure:: https://github.com/ameli/texplot/raw/main/docs/source/_static/images/plots/logistic.png
:align: left
:figwidth: 100%
:width: 100%
Show and Save Plots
===================
When working on a machine without display graphics, such as a remote server that lacks X11, displaying plots is not possible. Instead, plots should be saved. The `texplot.save_plot <https://ameli.github.io/texplot/generated/texplot.save_plot.html#texplot.save_plot>`__ function provides a simple wrapper around `matplotlib.pyplot.savefig <https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html>`__ to facilitate this. Additionally, the `texplot.show_or_save_plot <https://ameli.github.io/texplot/generated/texplot.show_or_save_plot.html#texplot.show_or_save_plot>`__ function attempts to display plots initially. If no graphical backend is available, it saves the plot instead. Additionally, you can configure it to both show and save the plot. Here is an example:
.. code-block:: python
>>> import matplotlib.pyplot as plt
>>> import texplot
>>> with texplot.theme(rc={'font.family': 'sans-serif'}):
>>>
>>> # Plot an example function
>>> fig, ax = plt.subplots()
>>> texplot.examples.lorenz(ax)
>>>
>>> # Show and save plot
>>> texplot.show_or_save_plot(plt, default_filename='lorenz.pdf',
... transparent_background=True, dpi=200,
... show_and_save=True, verbose=True)
plot saved to '/home/user/lorenz.pdf'.
.. figure:: https://github.com/ameli/texplot/raw/main/docs/source/_static/images/plots/lorenz.png
:align: left
:figwidth: 100%
:width: 100%
Test Package
============
|build-linux| |codecov-devel|
To test the package, first clone the source code from the repository and install the required test packages by:
.. code-block:: bash
git clone https://github.com/ameli/texplot.git
cd texplot
python -m pip install -r tests/requirements.txt
python -m pip install .
Then, test with `pytest <https://docs.pytest.org/>`__:
.. code-block:: bash
pytest
How to Contribute
=================
We welcome contributions via `GitHub's pull request <https://github.com/ameli/texplot/pulls>`_. If you do not feel comfortable modifying the code, we also welcome feature requests and bug reports as `GitHub issues <https://github.com/ameli/texplot/issues>`_.
License
=======
|license|
.. This package includes `Computer Modern <https://tug.org/FontCatalogue/computermodern/>`__ font for rendering :math:`\LaTeX`, which is distributed under `Knuth license <https://www.ctan.org/license/knuth>`__, a permissive license authored by Donald Knuth.
.. |logo| image:: https://raw.githubusercontent.com/ameli/texplot/main/docs/source/_static/images/icons/logo-texplot-light.svg
:width: 200
.. |deploy-docs| image:: https://img.shields.io/github/actions/workflow/status/ameli/texplot/deploy-docs.yml?label=docs
:target: https://github.com/ameli/texplot/actions?query=workflow%3Adeploy-docs
.. |deploy-docker| image:: https://img.shields.io/github/actions/workflow/status/ameli/texplot/deploy-docker.yml?label=build%20docker
:target: https://github.com/ameli/texplot/actions?query=workflow%3Adeploy-docker
.. |codecov-devel| image:: https://codecov.io/gh/ameli/texplot/graph/badge.svg?token=52HVURUBK1
:target: https://codecov.io/gh/ameli/texplot
.. |license| image:: https://img.shields.io/github/license/ameli/texplot
:target: https://opensource.org/licenses/BSD-3-Clause
.. |implementation| image:: https://img.shields.io/pypi/implementation/texplot
.. |pyversions| image:: https://img.shields.io/pypi/pyversions/texplot
.. |format| image:: https://img.shields.io/pypi/format/texplot
.. |pypi| image:: https://img.shields.io/pypi/v/texplot
.. |conda| image:: https://anaconda.org/s-ameli/texplot/badges/installer/conda.svg
:target: https://anaconda.org/s-ameli/texplot
.. |platforms| image:: https://img.shields.io/conda/pn/s-ameli/texplot?color=orange?label=platforms
:target: https://anaconda.org/s-ameli/texplot
.. |conda-version| image:: https://img.shields.io/conda/v/s-ameli/texplot
:target: https://anaconda.org/s-ameli/texplot
.. |conda-downloads| image:: https://img.shields.io/conda/dn/s-ameli/texplot
:target: https://anaconda.org/s-ameli/texplot
.. |tokei| image:: https://tokei.ekzhang.com/b1/github/ameli/texplot?category=lines
:target: https://github.com/ameli/texplot
.. |languages| image:: https://img.shields.io/github/languages/count/ameli/texplot
:target: https://github.com/ameli/texplot
.. |build-linux| image:: https://img.shields.io/github/actions/workflow/status/ameli/texplot/build-linux.yml
:target: https://github.com/ameli/texplot/actions?query=workflow%3Abuild-linux
.. .. |binder| image:: https://mybinder.org/badge_logo.svg
.. :target: https://mybinder.org/v2/gh/ameli/texplot/HEAD?filepath=notebooks%2Fquick_start.ipynb
Raw data
{
"_id": null,
"home_page": "https://github.com/ameli/texplot",
"name": "texplot",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "matplotlib plotting latex",
"author": "Siavash Ameli",
"author_email": "sameli@berkeley.edu",
"download_url": "https://files.pythonhosted.org/packages/ab/6c/6324753b4f111aea99855f084daddc669e89e220312c833717310fe7bfc2/texplot-0.0.7.tar.gz",
"platform": "Linux",
"description": "|logo|\n*********\n\n|deploy-docs|\n\n*texplot* is a python package to enhance *matplotlib* plots with publication-quality style.\n\nLinks\n=====\n\n* `Documentation <https://ameli.github.io/texplot>`__\n* `PyPI <https://pypi.org/project/texplot/>`__\n* `Anaconda <https://anaconda.org/s-ameli/texplot>`__\n* `Github <https://github.com/ameli/texplot>`__\n\nInstall\n=======\n\nThis package requires :math:`\\LaTeX` to be installed. Ensure that the ``latex`` executable is available on your system's ``PATH``.\n\nInstall with ``pip``\n--------------------\n\n|pypi|\n\n::\n\n pip install texplot\n\nInstall with ``conda``\n----------------------\n\n|conda-version|\n\n::\n\n conda install s-ameli::texplot\n\nSet Theme\n=========\n\n`texplot` can set theme either globally or locally:\n\nSet Theme Globally\n------------------\n\nCall `texplot.set_theme <https://ameli.github.io/texplot/generated/texplot.set_theme.html#texplot.set_theme>`__ function to set the *texplot* theme globally in your script:\n\n.. code-block:: python\n\n >>> import matplotlib.pyplot as plt\n >>> import texplot\n >>> texplot.set_theme()\n\n >>> # Plot an example function\n >>> fig, ax = plt.subplots()\n >>> texplot.examples.plot_function(ax)\n >>> plt.show()\n\n.. figure:: https://github.com/ameli/texplot/raw/main/docs/source/_static/images/plots/function.png\n :align: left\n :figwidth: 100%\n :width: 100%\n\nThe theme set as described above will affect your entire Python script for its duration. However, you can revert to the default *matplotlib* theme at any time by calling the `texplot.reset_theme <https://ameli.github.io/texplot/generated/texplot.reset_theme.html#texplot.reset_theme>`__ function as shown below:\n\n.. code-block:: python\n\n >>> # Resetting to default matplotlib theme\n >>> texplot.reset_theme()\n\n >>> # Plot another example function\n >>> fig2, ax2 = plt.subplots()\n >>> texplot.examples.plot_function(ax2)\n >>> plt.show()\n\n.. figure:: https://github.com/ameli/texplot/raw/main/docs/source/_static/images/plots/function_no_theme.png\n :align: left\n :figwidth: 100%\n :width: 100%\n\n\nSet Theme Within a Local Scope\n------------------------------\n\nThe `texplot.theme <https://ameli.github.io/texplot/generated/texplot.theme.html#texplot.theme>`__ function acts as a context manager, allowing you to apply the *texplot* theme within a specific local scope or function. The example below demonstrates setting the theme in a local scope. Outside of this scope, the default *matplotlib* theme remains unchanged.\n\n.. code-block:: python\n\n >>> import matplotlib.pyplot as plt\n >>> import texplot\n\n >>> with texplot.theme():\n >>> fig, ax = plt.subplots()\n >>> texplot.examples.plot_function(ax)\n >>> plt.show()\n\nSimilarly, you can use the context manager with a function. In the example below, the *texplot* theme is applied only within the ``plot()`` function. Outside this function, the default *matplotlib* theme remains unchanged.\n\n.. code-block:: python\n\n >>> import matplotlib.pyplot as plt\n >>> import texplot\n\n >>> @texplot.theme()\n >>> def plot():\n >>> fig, ax = plt.subplots()\n >>> texplot.examples.plot_function(ax)\n >>> plt.show()\n \n >>> plot()\n\nTheme Options\n=============\n\nYou can customize the theme by passing arguments to either the `texplot.set_theme <https://ameli.github.io/texplot/generated/texplot.set_theme.html#texplot.set_theme>`__ or `texplot.theme <https://ameli.github.io/texplot/generated/texplot.theme.html#texplot.theme>`__ functions. The parameters for both functions are identical and detailed in the `API reference <https://ameli.github.io/texplot/api.html>`__. The available arguments are as follows:\n\n.. list-table::\n :header-rows: 1\n\n * - Argument\n - Value\n - Description\n * - ``context``\n - ``'paper'``, ``'notebook'`` (default), ``'talk'``, or ``'poster'``\n - Adjusts font size and scales of the plot depending on the context.\n * - ``style``\n - See `matplotlib.style.available <https://matplotlib.org/stable/api/style_api.html#matplotlib.style.available>`__\n - Sets `matplotlib style <https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html>`__\n * - ``font_scale``\n - float (default is ``1``)\n - Scales the fonts.\n * - ``use_latex``\n - boolean (default is `True`)\n - If `True`, the mathematical symbols are rendered with :math:`\\LaTeX`.\n * - ``rc``\n - dictionary (default is ``{}``)\n - Passes any additional `matplotlib`'s `rcParam dictionary <https://matplotlib.org/stable/users/explain/customizing.html>`__.\n\nIn the example below, we configure a dark background style, increase the font size by a factor of 1.2, and set the font family to sans-serif:\n\n.. code-block:: python\n\n >>> import matplotlib.pyplot as plt\n >>> import texplot\n\n >>> with texplot.theme(\n ... rc={'font.family': 'sans-serif'},\n ... style='dark_background',\n ... font_scale=1.2):\n >>>\n >>> # Plot an example diagram\n >>> fig, ax = plt.subplots()\n >>> texplot.examples.plot_bifurcation_diagram(ax)\n >>> plt.show()\n\n.. figure:: https://github.com/ameli/texplot/raw/main/docs/source/_static/images/plots/logistic.png\n :align: left\n :figwidth: 100%\n :width: 100%\n\nShow and Save Plots\n===================\n\nWhen working on a machine without display graphics, such as a remote server that lacks X11, displaying plots is not possible. Instead, plots should be saved. The `texplot.save_plot <https://ameli.github.io/texplot/generated/texplot.save_plot.html#texplot.save_plot>`__ function provides a simple wrapper around `matplotlib.pyplot.savefig <https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html>`__ to facilitate this. Additionally, the `texplot.show_or_save_plot <https://ameli.github.io/texplot/generated/texplot.show_or_save_plot.html#texplot.show_or_save_plot>`__ function attempts to display plots initially. If no graphical backend is available, it saves the plot instead. Additionally, you can configure it to both show and save the plot. Here is an example:\n\n.. code-block:: python\n\n >>> import matplotlib.pyplot as plt\n >>> import texplot\n\n >>> with texplot.theme(rc={'font.family': 'sans-serif'}):\n >>>\n >>> # Plot an example function\n >>> fig, ax = plt.subplots()\n >>> texplot.examples.lorenz(ax)\n >>>\n >>> # Show and save plot\n >>> texplot.show_or_save_plot(plt, default_filename='lorenz.pdf',\n ... transparent_background=True, dpi=200,\n ... show_and_save=True, verbose=True)\n plot saved to '/home/user/lorenz.pdf'.\n\n.. figure:: https://github.com/ameli/texplot/raw/main/docs/source/_static/images/plots/lorenz.png\n :align: left\n :figwidth: 100%\n :width: 100%\n\nTest Package\n============\n\n|build-linux| |codecov-devel|\n\nTo test the package, first clone the source code from the repository and install the required test packages by:\n\n.. code-block:: bash\n\n git clone https://github.com/ameli/texplot.git\n cd texplot\n python -m pip install -r tests/requirements.txt\n python -m pip install .\n\nThen, test with `pytest <https://docs.pytest.org/>`__:\n\n.. code-block:: bash\n\n pytest\n\nHow to Contribute\n=================\n\nWe welcome contributions via `GitHub's pull request <https://github.com/ameli/texplot/pulls>`_. If you do not feel comfortable modifying the code, we also welcome feature requests and bug reports as `GitHub issues <https://github.com/ameli/texplot/issues>`_.\n\nLicense\n=======\n\n|license|\n\n.. This package includes `Computer Modern <https://tug.org/FontCatalogue/computermodern/>`__ font for rendering :math:`\\LaTeX`, which is distributed under `Knuth license <https://www.ctan.org/license/knuth>`__, a permissive license authored by Donald Knuth.\n\n.. |logo| image:: https://raw.githubusercontent.com/ameli/texplot/main/docs/source/_static/images/icons/logo-texplot-light.svg\n :width: 200\n.. |deploy-docs| image:: https://img.shields.io/github/actions/workflow/status/ameli/texplot/deploy-docs.yml?label=docs\n :target: https://github.com/ameli/texplot/actions?query=workflow%3Adeploy-docs\n.. |deploy-docker| image:: https://img.shields.io/github/actions/workflow/status/ameli/texplot/deploy-docker.yml?label=build%20docker\n :target: https://github.com/ameli/texplot/actions?query=workflow%3Adeploy-docker\n.. |codecov-devel| image:: https://codecov.io/gh/ameli/texplot/graph/badge.svg?token=52HVURUBK1\n :target: https://codecov.io/gh/ameli/texplot\n.. |license| image:: https://img.shields.io/github/license/ameli/texplot\n :target: https://opensource.org/licenses/BSD-3-Clause\n.. |implementation| image:: https://img.shields.io/pypi/implementation/texplot\n.. |pyversions| image:: https://img.shields.io/pypi/pyversions/texplot\n.. |format| image:: https://img.shields.io/pypi/format/texplot\n.. |pypi| image:: https://img.shields.io/pypi/v/texplot\n.. |conda| image:: https://anaconda.org/s-ameli/texplot/badges/installer/conda.svg\n :target: https://anaconda.org/s-ameli/texplot\n.. |platforms| image:: https://img.shields.io/conda/pn/s-ameli/texplot?color=orange?label=platforms\n :target: https://anaconda.org/s-ameli/texplot\n.. |conda-version| image:: https://img.shields.io/conda/v/s-ameli/texplot\n :target: https://anaconda.org/s-ameli/texplot\n.. |conda-downloads| image:: https://img.shields.io/conda/dn/s-ameli/texplot\n :target: https://anaconda.org/s-ameli/texplot\n.. |tokei| image:: https://tokei.ekzhang.com/b1/github/ameli/texplot?category=lines\n :target: https://github.com/ameli/texplot\n.. |languages| image:: https://img.shields.io/github/languages/count/ameli/texplot\n :target: https://github.com/ameli/texplot\n.. |build-linux| image:: https://img.shields.io/github/actions/workflow/status/ameli/texplot/build-linux.yml\n :target: https://github.com/ameli/texplot/actions?query=workflow%3Abuild-linux \n.. .. |binder| image:: https://mybinder.org/badge_logo.svg\n.. :target: https://mybinder.org/v2/gh/ameli/texplot/HEAD?filepath=notebooks%2Fquick_start.ipynb\n",
"bugtrack_url": null,
"license": null,
"summary": "Enhance your matplotlib plots with publication-quality style",
"version": "0.0.7",
"project_urls": {
"Documentation": "https://github.com/ameli/texplot/blob/main/README.rst",
"Download": "https://github.com/ameli/texplot/archive/main.zip",
"Homepage": "https://github.com/ameli/texplot",
"Source": "https://github.com/ameli/texplot",
"Tracker": "https://github.com/ameli/texplot/issues"
},
"split_keywords": [
"matplotlib",
"plotting",
"latex"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1640e763fe1ff7b5d76852f2d5f927565fcd97d460616008d5995968d3721900",
"md5": "90c74408052a090ae83780b9eb81fd1c",
"sha256": "9f054beacfff68b8304e3d499266aa31845e240e9cc69d37552e0d6c1cba1ba4"
},
"downloads": -1,
"filename": "texplot-0.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "90c74408052a090ae83780b9eb81fd1c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 16648,
"upload_time": "2024-12-14T04:39:40",
"upload_time_iso_8601": "2024-12-14T04:39:40.069216Z",
"url": "https://files.pythonhosted.org/packages/16/40/e763fe1ff7b5d76852f2d5f927565fcd97d460616008d5995968d3721900/texplot-0.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ab6c6324753b4f111aea99855f084daddc669e89e220312c833717310fe7bfc2",
"md5": "122de81bcbb34fa782f71ac119fc18e3",
"sha256": "2c96e8b8b510e5e4341507904a6a107b809fedff616bfe381535fd11ea093cde"
},
"downloads": -1,
"filename": "texplot-0.0.7.tar.gz",
"has_sig": false,
"md5_digest": "122de81bcbb34fa782f71ac119fc18e3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 18416,
"upload_time": "2024-12-14T04:39:42",
"upload_time_iso_8601": "2024-12-14T04:39:42.343844Z",
"url": "https://files.pythonhosted.org/packages/ab/6c/6324753b4f111aea99855f084daddc669e89e220312c833717310fe7bfc2/texplot-0.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-14 04:39:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ameli",
"github_project": "texplot",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [
{
"name": "matplotlib",
"specs": []
}
],
"lcname": "texplot"
}