Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to implement text word processing with matplotlib

Shulou Source: shulou.com Published: 2022-05-31 23:15:43 10月31日 Update

This article mainly introduces matplotlib how to achieve text word processing, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

1.4. Working with text

The text () command can add text anywhere, xlabel (), ylabel (), and title () add the x-axis, y-axis label and title, respectively.

Import numpy as npimport matplotlib.pyplot as plt# Fixing random state for reproducibilitynp.random.seed (19680801) mu, sigma= 100,15x = mu + sigma * np.random.randn (10000) # the histogram of the datan, bins, patches = plt.hist (x, 50, normed=1, facecolor='g', alpha=0.75) plt.xlabel ('Smarts') plt.ylabel (' Probability') plt.title ('Histogram of IQ') plt.text (60, .025, rang $\ mu=100,\\ sigma=15 $') plt.axis ([40,160,0) 0.03]) plt.grid (True) plt.show ()

All text () commands return an instance of matplotlib.text.Text, changing them through properties or setp ().

T = plt.xlabel ('my data', fontsize=14, color='red')

1.4.1 use of mathematical expressions

Plt.title (ringing $\ sigma_i=15 $')

The preceding r specifies that the string following it is the original string, and then uses a $package to indicate that the middle is a mathematical expression, and\ indicates the translation of a specific mathematical symbol.

4.2 Notes

The annotate () method provides an annotated method.

Annotate (string,xy,xytest,arrowprops)

Import numpy as npimport matplotlib.pyplot as pltax = plt.subplot (111t) t = np.arange (0.0,5.0,0.01) s = np.cos (2*np.pi*t) line, = plt.plot (t, s, lw=2) plt.annotate ('local max', xy= (2,1), xytext= (3,1.5), arrowprops=dict (facecolor='black', shrink=0.05),) plt.ylim (- 2Magne2) plt.show ()

By default, xy and xytext use the coordinates of the data, and you can specify other coordinate systems as well.

Thank you for reading this article carefully. I hope the article "how to achieve text word processing in matplotlib" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Text articles processing coordinates mathematics commands characters strings methods comments expressions originals values locations interests packages and at the same time instances attributes situations Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info Linux Apple Shulou Information