SoFunction
Updated on 2024-11-19

Python basic drawing tool matplotlib

Python drawing (line color, size, line shape)

Let's put the base code first and tell the effect below:

import  as plt
import numpy as np
 
list1=[1,2,6,4,5,6,2,4,4,5,7]
list2=[2,3,5,8,12,1,3,4,6,2,4]
['-serif']=['SimHei'] # Used to display Chinese labels properly
('Show Chinese title')
("Horizontal coordinates")
("Vertical coordinates")
x=(0,len(list1))+1       #// Get the length
x[0]=1                            #% Coordinates from 1
my_x_ticks = (1, 14, 1)  #! Controls the degree of gridding of the horizontal coordinates for a more pleasing display
(my_x_ticks)
(x,list1,label='list1',color='g')
(x,list2,label='list2',color='b')
()
()#Add grid
()
['-serif']=['SimHei'] #Used to display Chinese labels normally

Without this line of code I am displaying garbled tags inside vscode as shown below:

Line color setting and grid size label setting effect

(x,list1,label='list1',color='g')
(x,list2,label='list2',color='b')

Colors can be set and selected by yourself

my_x_ticks = (1, 14, 1)  #! Controls the degree of gridding of the horizontal coordinates for a more pleasing display
(my_x_ticks)

Gridded control coordinate distances are more aesthetically pleasing.

Tabs: that's what shows up in the upper right corner

Setting the size and style of lines

(x,list1,label='list1',color='Magenta',linewidth=2,linestyle='-.')# Add linestyle to set the line type
(x,list2,label='list2',color='DarkTurquoise',linewidth=4,linestyle='--')

The color reference URL is set randomly, and the effect is shown:

Line segment type:

Full Code:

import  as plt
import numpy as np
 
list1=[1,2,6,4,5,6,2,4,4,5,7]
list2=[2,3,5,8,12,1,3,4,6,2,4]
['-serif']=['SimHei'] # Used to display Chinese labels properly
('Show Chinese title')
("Horizontal coordinates")
("Vertical coordinates")
x=(0,len(list1))+1
x[0]=1
my_x_ticks = (1, 14, 1)
(my_x_ticks)
(x,list1,label='list1',color='Magenta',linewidth=2,linestyle='-.')# Add linestyle to set the line type
(x,list2,label='list2',color='DarkTurquoise',linewidth=4,linestyle='--')
()
()#Add grid
()

to this article on the foundation of python drawing artifacts matplotlib article is introduced to this, more related to python drawing matplotlib content, please search for my previous posts or continue to browse the following related articles I hope you will support me in the future more!