Python篇-绘图

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,2*np.pi,100)

y1,y2 = np.sin(x),np.cos(x)

plt.plot(x,y1)

plt.plot(x,y2)

plt.title("sanjiaohanshu")
plt.xlabel("x")
plt.ylabel("y")

plt.show()
复制代码

name_list = ["A","B","C","D","E"]
num_list = [1.6,0.5,7,3.4,9]
plt.bar(range(len(num_list)),num_list,color="ygbrc",tick_label=name_list)

plt.show()
复制代码

# 堆叠柱状图
name_list = ["A","B","C","D","E"]
num_list = [1.6,0.5,7,3.4,9]
num_list1 = [1,0.9,3.6,9,8]
plt.bar(range(len(num_list)),num_list,label="boy",fc ="c")
plt.bar(range(len(num_list1)),num_list1,label = "girl",fc="g")
plt.legend()
plt.show()
复制代码

# 并列柱状图
name_list = ["A","B","C","D","E"]
num_list = [1.6,0.5,7,3.4,9]
num_list1 = [1,0.9,3.6,9,8]
x = list(range(len(num_list)))
totle_width,n = 0.8,2
width = totle_width/n
plt.bar(x,num_list,width=width,label="boy",fc="y")
for i in range(len(x)):
    x[i] = x[i]+width
plt.bar(x,num_list1,width=width,label="girl",fc="b")
plt.legend()
plt.show()
复制代码

# 饼状图
labels = "A","B","C","D","E"
fracs = [15,25,10,67,66.4]
# 凸显数据
explode = [0,0,0.1,0.3,0]
plt.axes(aspect=1)
plt.pie(x=fracs,labels=labels,explode=explode,autopct="%3.4f%%",shadow=True,startangle=90)
plt.show()
复制代码


# 实时绘图
# ax = []
# ay = []
# plt.ion()
# for i in range(100):
#     ax.append(i)
#     ay.append(i**2)
#     # 清除
#     plt.clf()
#     plt.plot(ax,ay)
#     plt.pause(0.1)
# plt.ioff()
# plt.show()

复制代码

from mpl_toolkits.mplot3d import Axes3D

# 三维绘图
x = np.random.normal(0,1,100)
y = np.random.normal(0,1,100)
z = np.random.normal(0,1,100)
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(x,y,z)
plt.show()
复制代码

#OpenCV简单使用

import cv2
 
img = cv2.imread("pic.jpg")
# img = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)
# cv2.imshow("image",img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
#画线
green = (0,255,0)
# cv2.line(img,(0,0),(300,300),green,3)
# cv2.imshow("image",img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
#画矩形
# cv2.rectangle(img,(50,100),(150,200),green,5)
# cv2.imshow("image",img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
#画圆
cv2.circle(img,(150,150),100,green,3)
cv2.imshow("image",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite("tt.jpg",img)
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值