机器学习第五题0919

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()

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值