Giter Site home page Giter Site logo

highlight_text's Introduction

png

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):

import matplotlib.pyplot as plt
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 and if used call plt.tight_layout() before using the htext function. Otherwise the data transformation will not show properly.

Installation

pip install highlight-text

png

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

s: text including highlighted substrings
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

highlight_text's People

Contributors

znstrider avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.