In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use Matplotlib library in python. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.
Matplotlib is a Python 2D drawing library that generates publication quality data in a variety of hardcopy formats and cross-platform interactive environments.
Matplotlib is available for Python scripts, Python and IPython shells, Jupyter notebooks, Web application servers and four graphical user interface toolkits.
install python -m pip install -U pippython -m pip install -U matplotlib instance Draw a simple image import numpyfrom matplotlib import pyplotx = numpy.arange(1, 6)y = 2 * x + 10pyplot.title("Matplotlib")pyplot.xlabel("x axis")pyplot.ylabel("y axis") pyplot.plot(x, y)pyplot.show()
Draw points from matplotlib import pyplot#Draw scatter plot pyplot.scatter(2, 6)#Set output style pyplot.scatter(3, 5, s=200)pyplot.show()
Draw a series of points from matplotlib import pyplotx = [1, 5, 10, 15, 20]y = [10, 20, 30, 40, 50]pyplot.scatter(x, y, s=100)pyplot.show()
custom colors
Matplotlib allows you to assign colors to individual points in a scatterplot. The default is blue dots and a black outline, which works well when the scatterplot contains few data points. However, when drawing many points, black outlines may stick together.
from matplotlib import pyplotx = list(range(1, 1001))y = [x**2 for x in x]pyplot.scatter(x, y, c='red', edgecolor='none', s=40)#Set the range of values for each axis pyplot.axis([0, 1100, 0, 110000]) pyplot. show ()
histogram from matplotlib import pyplotimport numpyplot.figure(3)x_index = numpy.arange(5) #Index of bar x_data =('A ', ' B','C',' D','E') y1_data = (20, 35, 30, 35, 27)y2_data = (25, 32, 34, 20, 25)bar_width = 0.35 #Define a number representing the width of each individual column rects1 = pyplot.bar (x_index, y1_data, width=bar_width, alpha=0.4, color='b', label='legend 1') #Parameters: left offset, height, column width, transparency, color, legend rects2 = pyplot.bar (x_index + bar_width, y2_data, width=bar_width, alpha=0.5, color='r', label='legend 2')#Parameters: left offset, height, column width, transparency, color, legend #For left offset, don't care about the center of each column, because just set the tick mark in the middle of the column pyplot.xticks(x_index + bar_width/2, x_data) #x-axis tick pyplot.legend() #Display legend pyplot.tight_layout() #Automatically control the outer edges of the image, this method does not control the spacing between images pyplot.show()
line-related attribute tag sets linestyle or ls description '-' Solid line ':' Dotted line '-' Broken lines 'None','','' I don't draw anything. ' dot-dash line marker maker Description 'o' Circle'. ' dot 'D' Diamond's' Square 'h' Hexagon 1 '*' asterisk 'H' Hexagon 2 'd' Small diamond '_' Horizontal line 'v' Triangle '8' with corner down Octagon '' triangle with one corner to the right Pixel '^' Triangle '+' with corner up Plus '\ ' Vertical bar 'None','',' ' no 'x' X Color Abbreviations color 'b' Blue 'g' Green 'r' Red 'y' Yellow 'c' Cyan 'k' black 'm' magenta 'w' White about "how to use Matplotlib library in python" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
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.