import matplotlib.pyplot as plt
import numpy as np
#解决中文显示问题
plt.rcParams['font.sans-serif'] = ['KaiTi'] # 指定默认字体
plt.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题
x0 = 0.5
y0 = 2*x0
plt.scatter(x0, y0, s=50, color='r', lw = 3)#
plt.plot([x0, x0], [-6, y0], '--')#绘制注释线
x = np.linspace(-3, 3, 100)
y = 2*x
plt.xlim(-3, 3)#设置X轴范围
plt.ylim(-6, 6)#设置Y轴范围
plt.xlabel('I love machine learning', color='aqua', fontsize=20)#设置X轴标题
plt.ylabel('hello matplotlib', color='blue', fontsize=20)#设置Y轴标题
plt.annotate(r'2*0.5=1.0', xy=(0.5, 1.0),xycoords='data', xytext= (40, -30),textcoords='offset points'
, fontsize=16, arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad = .2'))#connectionstyle:设置箭头的形状,为直线或者曲线,候选项有'arc3','arc','angle','angle3',可以防止箭头被曲线内容遮挡
plt.text(-2.5, 2, "hpu-machine-learning", ha='left', rotation=0, wrap=True, fontsize=20, color="red")#mytext表示文档的位置,rotation表示旋转的角度
#plt.annotate("2*0.5=1.0", xy=(0.5, 1), mytext=(1, 0), textcoords='offset points')
plt.plot(x, y, color='red', linewidth=1.0, linestyle='-')#绘制图像,用实现绘制
plt.show()
机器学习第五题0919
最新推荐文章于 2023-03-19 15:35:36 发布