当前位置:网站首页>Matplotlib drawing tips

Matplotlib drawing tips

2022-06-21 12:46:00 Mark_ Aussie

Automatically close after displaying the graph

Use plt.show() If it is not closed manually, the program will get stuck ;

Problems encountered in practice : Use plt.show() After that, you can display the required diagram , If it is not used, it will not display correctly , But it needs to produce a large number of drawings , It can't be turned off manually , Instead of plt.show()

plt.pause(0.01)  #  Show seconds 
plt.close()

Automatic shutdown through multithreading fig Methods ( Fail to succeed )

matplotlib Call Multithread to turn off graphic display when drawing _ Xiaodongxie's blog -CSDN Blog _matplotlib Close after drawing

Set line type

Use plt.plot() Draw a straight line , You can use linestyle Set line type ;“:” Said the dotted line ( green ),“--” It's the dotted line ( blue )

Custom properties :color( Color )marker( The shape of the marker )linestyle( Line shape )linewidth( Line width )marksize( The size of the mark )label( label , For legend )

marker:S --> A solid square  P --> Solid Pentagram  O --> Solid round * --> Stars  D --> The diamond

linestyle:-  Solid line    Dotted line    Broken line  -.  Draw a dotted line

figure

Create a global drawing area ,facecolor=None Is a colorless background
plt.figure(figsize=None, facecolor=None)  # figsize(a,b) Parameters in a Is the width of the plot area ,b Is the height
 

Display Chinese and font settings :

Mark the median size of the drawing :

plt.text(a,b,b)  # data display x Corresponding position of shaft 、 The height of the displayed position ( You can adjust )、 The size of the displayed data value
for a, b in zip(x, highest): # Use for The loop outputs in turn zip() Corresponding connection
    plt.text(a, b + 2, b, ha=‘center’, va=‘bottom’)

 Insert picture description here

Reference resources :

https://www.csdn.net/tags/NtjaYgwsMTY2OTUtYmxvZwO0O0OO0O0O.html

​​​​​​python Drawing of bar and line charts , And display data _ The keyboard broke the blog with a salary of more than ten thousand -CSDN Blog _python How a bar graph displays data

原网站

版权声明
本文为[Mark_ Aussie]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211223594980.html