matplotlib库(4)

基本绘图函数

import matplotlib.pyplot as plt
import numpy as np

# 基本绘图函数
plt.figure(1)
# 直方图
plt.subplot(2, 2, 1)
x = 10 * np.random.randn(10)
bins = 10
range = (0, 10)
plt.hist(x, bins, range)
# 饼图
plt.subplot(2, 2, 2)
x = [10, 20, 30, 40]
explode = [0, 0.1, 0, 0]
labels = ["1", "2", "3", "4"]
colors = ["red", "blue", "green", "gray"]
autopct = "%.1f%%"
plt.pie(x, explode, labels, colors, autopct)
# 散点图
plt.subplot(2, 2, 3)
x = [10, 20, 30, 40]
y = [10, 20, 30, 40]
s = [100, 20, 40, 20]
c = ["red", "blue", "green", "gray"]
marker = "v"
plt.scatter(x, y, s, c, marker)
# 条形图
plt.subplot(2, 2, 4)
x = [10, 20, 30, 40]
height = [10, 5, 6, 8]
width = 1
plt.bar(x, height, width)

plt.figure(2)
# 极坐标图
theta = [0.25*np.pi, 0.5*np.pi]
r = [5, 8]
plt.polar(theta, r)

plt.show()

显示结果

在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_49346755/article/details/121256039