Skip to main content

matplotlib functions to plot text with color highlighted substrings

Project description

highlight_text

This package provides two functions that allow you to plot text with in matplotlib:

  • htext for plotting onto an axes in data coordinates.
  • fig_htext for plotting onto the figure in figure coordinates.

They take a string with substring delimiters = ['<', '>'] to be highlighted according to highlight colors: 'The weather is (sunny) today. Yesterday it (rained).', color = 'k', highlight_colors = ['C1', 'grey'] prints the text with 'sunny' as orange and 'rained' as grey.

A minimal example would be (Replace () with delimiters <> - markdown won't show them):

from highlight_text.htext import htext, fig_htext

fig, ax = plt.subplots()  
htext(s = 'The weather is (sunny) today. Yesterday it (rained).',
          x = 0, y = 0.5,
          color = 'k', highlight_colors = ['C1', 'grey'])

or for the fig_htext:

fig, ax = plt.subplots()  
fig_htext(s = 'The weather is (sunny) today. Yesterday it (rained).',
              x = 0, y = 0.5,
              color = 'k', highlight_colors = ['C1', 'grey'])

You can further highlight by using
highlight_styles ie. ['normal', 'italic', 'oblique']
and highlight_weights ie. ['regular', 'bold'].

This does work with linebreaks \n, fstrings and ha in ['left', 'right', 'center'] as well as va in ['botton', 'top', 'center'].

Make sure to set data limits before using this function. Otherwise the data transformation will not work properly.

Installation

pip install highlight-text

png

Parameters:
##########

s: text including
x: x position with left alignment
y: y position
color: textcolor of unhighlighted text
highlight_colors: list of highlight colors
highlight_weights = ['regular']: the fontweight used for highlighted text
highlight_styles = ['normal']: the fontstyle used for highlighted text
string_weight = 'regular': the fontweight used for normal text
string_style = 'normal': the fontstyle used for normal text
delim = ['<', '>']: delimiters to enclose the highlight substrings
va = 'bottom', textalignment has to be in ['bottom', 'top', 'center']
ha = 'left', textalignment has to be in ['left', 'right', 'center']
hpadding = 0: extra padding between highlight and normal text
linespacing = 0.25: linespacing in factor of font height between rows
**kwargs: figure.text | plt.text kwargs
[ax: axes to draw the text onto (in case of htext)]
[fig: figure(in case of fig_htext)]

Returns:
##########

a list of texts

Alt Text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

highlight_text-0.0.4.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

highlight_text-0.0.4-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file highlight_text-0.0.4.tar.gz.

File metadata

  • Download URL: highlight_text-0.0.4.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.3

File hashes

Hashes for highlight_text-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c7bdcd7c562ae9da2e4f3c96597da5d0fdc4cdd2d82d09d695cab531695a54f4
MD5 637d3a94b85675f67ecc1f10fde6315c
BLAKE2b-256 851f2d57c6db81071033fe9b39d9d75b788bd5c2b7e8df2781fbcfc01540dc34

See more details on using hashes here.

File details

Details for the file highlight_text-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: highlight_text-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.3

File hashes

Hashes for highlight_text-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c82f82a5dfd0d8e72c292779137c4ce2de08d0a9c4435849bd195969d06a2296
MD5 698bdbdbb1f205a1c7589cfa48eca766
BLAKE2b-256 3a11e540a015f4d770a798ea895de564a0159a8cb8a2d5ce43fd5e9c5cc77c01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page