Let’s draw a histogram and mark the value corresponding to the data on the graph. Plt.scatter(x, y, s = 50, c = colour, alpha = 0.8) Finally, a color bar is added through colorbar (). Also use the subplot () method to select the drawing paper and draw Īx2.plot(x, z, 'co-', linewidth = 1, markersize = 2)Īx3.plot(x, y_sin, color = 'blue', marker = '+', linestyle = 'dashed')įirst, the points x and y of the data to be drawn are generated, then an array size of control size is generated for each data point, and then an array color of control color is generated for each data point.Use the subplot () method to create a drawing paper, and select the current drawing paper and draw, parameter 1 number of rows, parameter 2 number of columns, parameter 3 selects the drawing paper, such as: ax1 = fig.add_subplot(221).Use the figure () method to create a drawing board 1.So, how do you use Python to draw multiple sub-pictures on one artboard? If you do not declare the artboard in advance, the default is to create one artboard and one drawing paper. Plt.plot(x, y_cos, marker = '+', linestyle = '-', label = 'y_cos') Plt.plot(x, y_sin, color = "red", linewidth = 1.5, linestyle = "-.", label = "y_sin")
Line graph Draw multiple graphics in one drawing. The following introduces several two-dimensional graphs often drawn with matplotlib. The basic usage of matplotlib will not be introduced in detail. When using any third-party library in Python, you must first import. This article introduces the use of matplotlib to draw different two-dimensional graphics.īasic drawing process: -Create the canvas -Add title, add X axis and Y axis name, modify the scale and range of X axis and Y axis -Draw graphics and adjust the graphic style -Add legend -Display picture after drawing -Save Picture Based on this state machine environment, we can create graphics. The top layer is the matplotlib “state machine environment” provided by pyplot. Everything in matplotlib is organized according to hierarchical results. The state machine implicitly automatically creates numbers and coordinate axes to achieve the required drawing. Pyplot is a submodule of matplotlib, which mainly provides a state machine interface for the underlying object-oriented drawing library. It was installed when matplotlib was installed. Numpy is a Python library for mathematical operations.
It contains a large number of tools that can be used to create a variety of graphics, including simple linear graphs, scatter plots, sinusoids, and even three-dimensional graphs. We can easily use it as a drawing control and embed it in a GUI application. It provides a similar set of command APIs, which is very suitable for interactive drawing. Python Dictionaries Access Items Change Items Add Items Remove Items Loop Dictionaries Copy Dictionaries Nested Dictionaries Dictionary Methods Dictionary Exercise Python If.Else Python While Loops Python For Loops Python Functions Python Lambda Python Arrays Python Classes/Objects Python Inheritance Python Iterators Python Scope Python Modules Python Dates Python Math Python JSON Python RegEx Python PIP Python Try.Matplotlib is a Python-based plotting library similar to Matlab.