程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python simple graph drawing

編輯:Python

Draw a scatter plot

import matplotlib.pyplot as plt
x_values = [1, 2, 3, 4, 5]
y_values = [1, 4, 9, 16, 25]
# Draw a scatter plot
# plt.scatter(x_values, y_values, s=100)
plt.scatter(x_values, y_values, marker='v') #marker To display the shape of drawing points D The diamond o function v triangle
plt.show()


Draw line chart

import matplotlib.pyplot as plt
x_values = [1, 2, 3, 4, 5]
y_values = [1, 4, 9, 16, 25]
# Broken line diagram
# Format :plt.plot(x,y)
plt.plot(x_values, y_values, marker='o')
plt.show()


Realize dynamic drawing

import matplotlib.pyplot as plt
import random
plt.ion() # Turn on interactive mode The key to success
plt.figure(1)
t = [0]
y = [0]
for i in range(2000):
plt.clf() # Empty everything on the canvas
t.append(random.randint(1, 10))
y.append(random.randint(1, 10))
plt.plot(t, y, '-r')
plt.pause(0.01)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved