In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to draw charts with Matplotlib in Python". Xiaobian shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how to draw charts with Matplotlib in Python" can help you solve the problem.
preface
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 an object-oriented drawing API that makes it easy to embed graphics in applications with Python GUI toolkits such as PyQt, WxPython, and Tkinter. It is also supported as scripts for Python, IPython Shell, Jupyter Notebook, and Web application servers.
Line Chart Drawing and Display #Show Weather for a Week #1. Create Canvas plt.figure (figsize =(20,8))#plt. figure (figsize =(), dpi =)#figsize: Specify the length and width of the image #dpi: Image sharpness #Return fig object #2. Draw image plt. plot ([1,2,3,4,5,6,7],[17,17,18,15,11,11,13], label ="hh ")#plt. plot (x, y, color =, line)#figure, axes = plt. subplots (nrows = 1, ncols = 2, figsize =(20,8), dpi = 80)#Show legend plt. legend (loc =" lower left ")#Add grid display plt. grid (True, linestyle ='-', alpha = 0.5)#3. Save images must precede show because show frees image resources #plt. savefig (" test.png ")#4. Show images plt.show ()
Draw math function image import numpy as np #1. Prepare x, y data x = np. linspace (-1,1,1000) y = 2 * x * x #2. Create canvas plt. figure (figsize =(20,8), dpi = 80)#3. Draw image plt. plot (x, y)#4. Display image plt.show ()
from Jupyterthemes import www.example.com (theme ='monokai ')#Select a drawing theme import matplotlib. pyplot as plt #The following code is required for individual environments % matplotlib inlineplt. figure () plt. plot ([1,0,9],[4,5,6]) plt.show ()
Scatter Plot Drawing #1. Prepare data x, y =[1,2,3,4,5,6,7],[17,17,18,15,11,11,13]#2. Create canvas plt. figure (figsize =(20, 8))#3. Draw image plt. scatter (x, y)#4. Display image plt.show ()
Draw histogram #1. Prepare data x, y =[1,2,3,4,5,6,7],[17,17,2,15,11,13]#2. Create canvas plt. figure (figsize =(20,8))#3. Draw image plt.bar (x, y, width = 0.5,color =['r ',' b','y',' g'])#4. Display image plt.show ()
Draw a histogram x =[1,2,3,4,5,6,17,17,18,15,11,45,12,54,23,45,6,12,87,51,11,13] plt. figure (figsize =(20,8), dpi = 80) distance = 2group_num = int ((max (x)-min (x))/distance) plt. hist (x, bins = group_num) plt.show ()
pie chart #1. Prepare data x, y =[1,2,3,4,5,6,7],['17',' 17','2',' 15','11',' 11','13']#2. Create canvas plt. figure (figsize =(20, 8))#3. Draw image plt. pie (x, labels = y, autopct ='%1.2f %%', colors =[' r','b',' y','g'])#x, y-axis scale equal length plt. axis ('equal ') plt. legend (loc ="lower left ")#4. Display image plt.show ()
That's all for "How to draw a chart with Matplotlib in Python". Thank you for reading it. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.
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.