{"id":17201990,"url":"https://github.com/tomicapretto/flexitext","last_synced_at":"2025-04-04T08:05:11.591Z","repository":{"id":39792742,"uuid":"407341088","full_name":"tomicapretto/flexitext","owner":"tomicapretto","description":"Flexitext: Draw styled text in Matplotlib","archived":false,"fork":false,"pushed_at":"2025-01-26T14:35:11.000Z","size":1413,"stargazers_count":119,"open_issues_count":8,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T07:08:46.479Z","etag":null,"topics":["matplotlib","python","text"],"latest_commit_sha":null,"homepage":"https://tomicapretto.github.io/flexitext/","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/tomicapretto.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2021-09-16T23:18:34.000Z","updated_at":"2025-02-03T18:55:10.000Z","dependencies_parsed_at":"2025-02-07T04:01:08.849Z","dependency_job_id":"0f816345-73c5-426c-9bbc-377d9f0139e2","html_url":"https://github.com/tomicapretto/flexitext","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomicapretto%2Fflexitext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomicapretto%2Fflexitext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomicapretto%2Fflexitext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomicapretto%2Fflexitext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomicapretto","download_url":"https://codeload.github.com/tomicapretto/flexitext/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142062,"owners_count":20890652,"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":["matplotlib","python","text"],"created_at":"2024-10-15T02:13:16.979Z","updated_at":"2025-04-04T08:05:11.554Z","avatar_url":"https://github.com/tomicapretto.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://raw.githubusercontent.com/tomicapretto/flexitext/main/docsite/logo.png\" width=420/\u003e\n\n[![PyPI - Version](https://img.shields.io/pypi/v/flexitext.svg)](https://pypi.org/project/flexitext/)\n[![Build Status](https://github.com/tomicapretto/flexitext/actions/workflows/tests.yml/badge.svg)](https://github.com/tomicapretto/flexitext/actions/workflows/tests.yml)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)\n[![codecov](https://codecov.io/gh/tomicapretto/flexitext/branch/main/graph/badge.svg?token=ZqH0KCLKAE)](https://codecov.io/gh/tomicapretto/flexitext)\n\n\n\n# Introduction\n\nFlexitext is a Python library that makes it easier to draw text with multiple styles in Matplotlib. This library is inspired and influenced by the R package [`ggtext`](https://wilkelab.org/ggtext/).\n\n\n## Installation\n\nFlexitext requires a working Python interpreter (3.7+). This library can be installed using pip:\n\n    pip install flexitext\n\nAlternatively, you can install the development version from GitHub:\n\n    pip install git+https://github.com/tomicapretto/flexitext.git\n\n\nFlexitext only requires Matplotlib version 3.4 or higher.\n\n\n## Overview\n\nAlbeit being inspired on [ggtext](https://wilkelab.org/ggtext/), Flexitext does not use HTML, CSS, or Markdown to specify text styles. On the contrary, it implements a tag-based styling that looks similar to HTML tags, but is not exactly like HTML. These formatted strings consist of three components:\n\n* An opening tag that defines the styles to apply.\n* The text to be styled.\n* A closing tag, indicating the extent to which the styles in the opening tag apply.\n\nLet's see an example:\n\n```python\n\"\u003ccolor:blue, size:16\u003eThis is blue text\u003c/\u003e and this is regular text\"\n```\n\n* \u003ccode\u003e\u0026lt;color:blue, size:16\u003e\u003c/code\u003e is the opening tag. Styles are key-value pairs separated by `:`. Multiple styles are separated by commas.\n* `This is blue text` is the text block. This text is going to be drawn using a font size of 16 and blue color.\n* \u003ccode\u003e\u0026lt;/\u003e\u003c/code\u003e is the closing tag. Only the text within the opening and the closing tags is formatted.\n\nAnd finally we have ` and this is regular text`. This is going to be drawn using the default style because it is not contained within any formatting tags.\n\n\n## Examples\n\nThe easiest way to use `flexitext` is through the `flexitext` function.\n\n\n```python\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\n\nfrom flexitext import flexitext\n\nmpl.rcParams['figure.facecolor'] = 'w'\n```\n\n\n```python\nfig, ax = plt.subplots(figsize=(9, 6))\n\ntext = \"Normal text\"\nax.text(0.5, 0.7, text, size=24, ha=\"center\")\n\ntext = \"\u003cweight:bold, size:24\u003eBold text\u003c/\u003e\"\nflexitext(0.5, 0.6, text, ha=\"center\")\n\ntext = \"\u003cstyle:italic, size:24\u003eItalic text\u003c/\u003e\"\nflexitext(0.5, 0.5, text, ha=\"center\")\n\ntext = \"\u003cweight:bold, size:24\u003eBold and\u003c/\u003e \u003cstyle:italic, size:24\u003eitalic too!\u003c/\u003e\"\nflexitext(0.5, 0.4, text, ha=\"center\");\n```\n\n\n    \n![png](README_files/README_2_0.png)\n    \n\n\nStyles can be nested\n\n\n```python\nfig, ax = plt.subplots(figsize=(9, 6))\n\ntext = \"\u003csize:28, color:royalblue\u003eIt is much \u003cweight:bold\u003eeasier \u003c/\u003e\u003cstyle:italic\u003enow\u003c/\u003e\u003c/\u003e\"\nflexitext(0.5, 0.6, text, ha=\"center\");\n```\n\n\n    \n![png](README_files/README_4_0.png)\n    \n\n\nA more convoluted example:\n\n\n```python\ntext = (\n    \"\u003csize:28, color:blueviolet, name:Montserrat\u003eYou can write using\\n\u003c/\u003e\"\n    \"\u003ccolor:grey, size:24\u003emultiple formats,\\nand linebreaks\\n\\n\"\n    \"\u003ccolor:royalblue, name:Montserrat\u003ealso \u003cweight:bold\u003ebold text\\n\\n\u003c/\u003e\u003c/\u003e\"\n    \"\u003cname:Montserrat\u003eand why not \u003ccolor:royalblue, style:italic\u003eitalics\u003c/\u003e too\u003c/\u003e\u003c/\u003e\"\n)\n\nfig, ax = plt.subplots(figsize=(9, 6))\nflexitext(0.5, 0.5, text, ha=\"center\", ma=\"center\");\n```\n\n\n    \n![png](README_files/README_6_0.png)\n    \n\n\nUse the figure fraction coordinates to write a formatted title.\n\n\n```python\nfig, ax = plt.subplots(figsize=(9, 6))\nfig.subplots_adjust(top=0.8, left=0.025)\n\nx = [1, 2, 3]\ny_blue = [2, 2.7, 4.5]\ny_red = [1, 3, 2.5]\n\n\nax.scatter(x, y_blue, color=\"royalblue\", s=120)\nax.scatter(x, y_red, color=\"crimson\", s=120)\n\n# Add flexitext\ntext = (\n    \"\u003cname:Montserrat\u003e\u003csize:24\u003eA \u003cweight:bold\u003egreat chart\u003c/\u003e showing\u003c/\u003e\\n\"\n    \"\u003csize:18\u003ethe values for the \"\n    \"\u003ccolor:royalblue, weight:bold\u003eblues\u003c/\u003e and the \u003ccolor:crimson, weight:bold\u003ereds\u003c/\u003e\u003c/\u003e\u003c/\u003e\"\n)\nflexitext(0.025, 0.8, text, va=\"bottom\", xycoords=\"figure fraction\");\n```\n\n\n    \n![png](README_files/README_8_0.png)\n    \n\n\n## Notes\n\nFlexitext only supports the following styles\n\n* alpha\n* backgroundcolor\n* color\n* family\n* name\n* size\n* style\n* weight\n\nSee [Matplotlib's documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.text.html#matplotlib.axes.Axes.text) for more information about their meaning and available values.\n\nFlexitext logo is created with Flexitext and Matplotlib (see [here](https://github.com/tomicapretto/flexitext/tree/main/docsite/logo.ipynb)).\n\n## Related work\n\n* [highlight_text](https://github.com/znstrider/highlight_text): Flexitext and highlight_text have similar goals. This library, highlight_text, allows you to customize more aspects of the highlighted text, such as the bounding box of the text or the border of the text with path effects. On the other hand, it requires you to pass a styles as a separated list of dictionaries instead of within the text. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomicapretto%2Fflexitext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomicapretto%2Fflexitext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomicapretto%2Fflexitext/lists"}