python画图

散点图

在这里插入图片描述

import  matplotlib.pyplot as plt
import numpy as np 

plt.rcParams['font.sans-serif']=['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False # 用来正常显示负号


t=np.arange(0.0, 2.0, 0.1)
s=np.sin(t*np.pi)


plt.figure(figsize=(8,8), dpi=80)
plt.figure(1)

ax1 = plt.subplot(2, 2, 1) # 指定子图的位置, 4行3列的图中第几个图
x = [0.55, 0.52] 
y = [0.75, 0.42] 
ax1.scatter(x, y, color="r",linestyle = "--")
plt.xlabel('time 1(s)')

# ax2 = plt.subplot(222)
ax2 = plt.subplot(2, 2, 2) # 指定子图的位置, 4行3列的图中第几个图
ax2.scatter(t,s,color="y",linestyle = "-")
for i in range(len(t)):
    rdx = np.random.randint(0, 2)
    rdy = np.random.randint(0, 2)
    if rdx == 0:
        rdx = -1
    if rdy == 0:
        rdy = -1
    # 设置点的标签, 随机偏移标签的位置,并设置大小
    plt.annotate(str(t[i])[0:4], xy = (t[i], s[i]), xytext = (t[i]+0.1*rdx, s[i]-0.1*rdy), fontsize=4)
ax1.set_xlim([0, 1])   # 设置x轴范围
ax1.set_ylim([0, 1.1]) # 设置y轴范围
plt.xticks(fontsize=7) # 设置x轴字体大小
plt.yticks(fontsize=7)

plt.xlabel("fig2", fontsize=8) # 设置x轴标签大小


ax3 = plt.subplot(2, 2, 3) 
ax3.scatter(t,s,color="g",linestyle = "-.")
plt.xlabel('time 3(s)')

ax4 = plt.subplot(2, 2, 4)
ax4.scatter(t,s,color="b",linestyle = ":")
plt.xlabel('time 4(s)')


# 调整子图间距
# plt.subplots_adjust(top=0.99, bottom=0.05, left=0.045, right=0.99, hspace=0.36, wspace=0.215)

plt.savefig("path")
# plt.savefig("path", dpi=300) # 设置dpi调节图片分辨率

plt.show()
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ystraw_ah

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值