SoFunction
Updated on 2024-11-19

matplotlib common functions, the use of matshow (axis settings)

1、

plt() uses an rc configuration file to customize various default attributes of the graph, called "rc configuration" or "rc parameters".
The rc parameter allows you to modify default attributes, including form size, points per inch, line width, color, style, axes, coordinate and network attributes, text, fonts, etc. The rc parameter is stored in a dictionary variable and is accessed by means of a dictionary.

Code:

import numpy as np
import  as plt
###%matplotlib inline #jupyter works so that you don't have to()
 
# Generate data
x = (0, 4*)
y = (x)
# Set the rc parameter to display the Chinese title
#Set the font to SimHei to display Chinese
['-serif'] = 'SimHei'
# Setting up the normal display of characters
['axes.unicode_minus'] = False
('sin curve')
# Set the line style
[''] = '-.'
# Set the line width
[''] = 3
# Plotting sin curves
(x, y, label='$sin(x)$')
 
('')
()

Parameters:

[''] = 300 #Picture Pixels
[''] = 300 #Resolution
(‘plot123_2.png', dpi=200)# Specify resolution
# Default pixels: [6.0,4.0], resolution 100, image size 600&400
# Specify dpi=200, image size 1200*800
# Specify dpi=300, image size 1800*1200
 
 
[''] = (8.0, 4.0)    # Image display size
[''] = 'nearest' # Nearest Neighbor Difference: pixels are squares
#Interpolation/resampling, or interpolation, is an image processing method that increases or decreases the number of pixels for a digital image.
 
[''] = 'gray' # Use grayscale output instead of color
 
('off')  #Printing images without displaying axes

from:https:///article/

For more detailed configuration see:/swuly302/blog/94805

2, matshow function

This is a function that draws a matrix: the(Afignum=None**kwargs)

A is the drawn matrix, where one matrix element corresponds to one image pixel.

Example:(Mat,  cmap=), cmap represents a color mapping method.

 

Example:

(A, "r-+", linewidth=2, label="train")
  (B, "b-", linewidth=3, label="val")
  (loc="upper right", fontsize=14)  # Set position
  ("Training set size", fontsize=14) # Tags
  ("RMSE", fontsize=14) 
([0, 80, 0, 3])# indicates the range of graphics to be displayed
((0, 81, step=20))#Set the scale
((0, 4, step=1))

What is the relationship between Axes - Subplot - Axis?

There are several concepts you need to know to use mapping:

  • Drawing board / canvas: this is a base carrier, similar to the actual drawing board, created with the () function, the program allows the creation of multiple drawing boards, the specific operation of the drawing board to follow the principle of proximity (the operation is implemented on the most recent call to the drawing board), the default conditions of the internal default call (1).
  • graphic area / drawing area: the actual area used to draw, generally not directly access, directly set the way ([x, y, w, h]), i.e., axes function directly determines the location of the area in the drawing board / canvas for x,y dimensions for w,h
  • Label area: used to show the graphic related labels, generally not directly set (not carefully studied), the region according to the graphic area for the expansion of the region, and the region is associated with the function (), (), (), etc.
fig = () 
()
 
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)

To make an analogy between drawing board and drawing paper, figure is like a drawing board, which is the carrier of the drawing paper, but the actual drawing and other operations are done on the drawing paper. In pyplot, the concept of paper corresponds to Axes/Subplot.

Contrast.

figure (1) VS figure()
The figure() operation is to create or call the drawing board, by default the system will create figure(1) as the drawing board. By default, the system will create figure(1) as the drawing board. When using this operation, follow the proximity principle, all drawing operations are realized on the most recently invoked drawing board.

axes() VS subplot()
([x, y, w, h]) is a function used to confirm the position and size of the graphic area on the drawing board. x,y denote the coordinates of the lower-left corner of the graphic area relative to the drawing board, and w,h denote the width and height of the graphic area. (By default, this operation operates on figure(1).)

(abc) is also used to confirm the essence of the graphic area on the drawing board location size of the function, the difference is that the function will draw the board according to the a line b columns, and then numbered line by line, and select the number of the region as a graphic area used to draw the area c. This is an axes () operation of advanced encapsulation for user convenience. This is an axes () operation of the advanced package, user-friendly. subplot (233) that 2 rows and 3 columns of the third position (that is, the first row of the third region)

At the same time, the actual area displayed by () is the smallest enclosing area of all graphical areas on the drawing board, not the entire board, i.e., if only subplot(224) is called the result will only display area 4 in the lower right corner, not 1, 2, 3, and 4, and thus there will be a certain illusion.

axes() VS axis()
axes([x, y, w, h]) is used to set the graphics area; the

axis([x_left, x_right, y_bottom, y_top]) is used to set the size of the window of the drawn graphic, indicating that the direct display of the graphic is required to meet the value of the range of the parameter, the visual representation of the actual display of the drawing area is the range of coordinates.

Note: The graphic area of the AXIS role continues to adhere to the proximity principle.

subplot() VS plot()
subplot is used to generate the graph area; the

plot is the actual use of the plotting function, similar functions have hist, etc., plot operation to comply with the principle of proximity, that is, the role of the most recent use of the graphics area.

Official website:/api/_as_gen/

to this common function of matplotlib, the use of matshow (axis settings) of the article is introduced to this, more related matplotlib, matshow content, please search for my previous posts or continue to browse the following articles I hope you will support me in the future!