In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to use Matplotlib, the essential library of python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Foreword:
Matplotlib, which is usually used with NumPy and Pandas, is one of the indispensable tools in data analysis.
Matplotlib is a MATLAB-like drawing tool in Python, and if you are familiar with MATLAB, you can quickly become familiar with it. Matplotlib provides a set of API for object-oriented drawing, which can easily embed graphics in applications with Python GUI toolkits (such as PyQt,WxPython, Tkinter). At the same time, it also supports scripting on servers for Python, IPython Shell, Jupyter Notebook and Web applications.
Official website address:
Https://matplotlib.org/
You can take a look at docs
The official website is quite detailed, you can refer to the official website directly.
1. Installation method
Pip installation:
Pip3 install matplotlib-I https://pypi.tuna.tsinghua.edu.cn/simple
Conda installation:
Conda install matplotlib
Whether the test was successful:
Import numpy as np from matplotlib import pyplot as plt x = np.arange (1m 11) y = 2 * x + 5 plt.title ("Matplotlib demo") plt.xlabel ("x axis caption") plt.ylabel ("y axis caption") plt.plot (x Magi y) plt.show ()
If you successfully appear in the following picture, you can start to transform it.
two。 Make good use of the official website example the simplest application-line chart fig, ax = plt.subplots () # Create a figure containing a single axes.ax.plot ([1,2,3,4], [1,4,2,3]); # Plot some data on the axes.
The annotated method fig, ax = plt.subplots (figsize= (5,2.7)) t = np.arange (0.0,5.0,0.01) s = np.cos (2 * np.pi * t) line, = ax.plot (t, s, lw=2) ax.annotate ('local max', xy= (2,1), xytext= (3,1.5), arrowprops=dict (facecolor='black', shrink=0.05)) ax.set_ylim (- 2,2)
Histogram-Bar Labelimport matplotlib.pyplot as pltimport numpy as npN = 5menMeans = (20,35,30,35,-27) womenMeans = (25,32,34,20,-25) menStd = (2,3,4,3,3) womenStd = (3,5,2,3,3) ind = np.arange (N) # the x locations for the groupswidth = 0.35 # the width of the bars: can also be len (x) sequencefig, ax = plt.subplots () p1 = ax.bar (ind, menMeans, width, yerr=menStd) Label='Men') p2 = ax.bar (ind, womenMeans, width, bottom=menMeans, yerr=womenStd, label='Women') ax.axhline (0, color='grey', linewidth=0.8) ax.set_ylabel ('Scores') ax.set_title (' Scores by group and gender') ax.set_xticks (ind, labels= ['G1,'G2,'G3,'G4') ) ax.legend () # Label with label_type 'center' instead of the default' edge'ax.bar_label (p1, label_type='center') ax.bar_label (p2, label_type='center') ax.bar_label (p2) plt.show ()
The following figure appears for a normal run:
CSD of line chart
Calculate the cross spectral density Compute the cross spectral density of two signals of two signals
Import numpy as npimport matplotlib.pyplot as pltfig, (ax1, ax2) = plt.subplots (2,1) # make a little extra space between the subplotsfig.subplots_adjust (hspace=0.5) dt = 0.01t = np.arange (0,30) Dt) # Fixing random state for reproducibilitynp.random.seed (19680801) nse1 = np.random.randn (len (t)) # white noise 1nse2 = np.random.randn (len (t)) # white noise 2R = np.exp (- t / 19680801) cnse1 = np.convolve (nse1, r, mode='same') * dt # colored noise 1cnse2 = np.convolve (nse2, r Mode='same') * dt # colored noise two signals with a coherent part and a random parts1 = 0.01* np.sin (2 * np.pi * 10 * t) + cnse1s2 = 0.01* np.sin (2 * np.pi * 10 * t) + cnse2ax1.plot (t, S1, t, S2) ax1.set_xlim (0,5) ax1.set_xlabel ('time') ax1.set_ylabel (' S1 and S2') ax1.grid (True) cxy, f = ax2.csd (S1, S2, 256) 1. / dt) ax2.set_ylabel ('CSD (db)') plt.show ()
This is the end of the content of "how to use Matplotlib, a must-have library for python". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.