python matplotlib

import numpy as np
import matplotlib.pyplot as plt

v1 = 10
v2 = 14
x = np.array([-4,-3,-2,-1,0,1,2,3,4])
y = np.array([v1,v1,v1,0,0,0,v2,v2,v2])
plt.plot(x,y,'b')# 折线 1 x 2 y 3 color
plt.xticks(())

plt.xlabel('time(s)')
plt.ylabel('speed(m/s)')

# 移动坐标轴,spines为脊梁,即4个边框
ax = plt.gca()  # gca stands for 'get current axis'
ax.spines['right'].set_color('none')  # 设置右‘脊梁’为无色
ax.spines['top'].set_color('none')  # 设置上‘脊梁’为无色
ax.xaxis.set_ticks_position('bottom')  # 底部‘脊梁’设置为X轴
ax.spines['bottom'].set_position(('data', 0))  # 底部‘脊梁’移动位置,y的data
ax.yaxis.set_ticks_position('left')  # 左部‘脊梁’设置为Y轴
ax.spines['left'].set_position(('data', 0))  # 左部‘脊梁’移动位置,x的data

#
plt.scatter([-3], [v1], 40, 'r')
plt.scatter([3], [v2], 40, 'r')

#
plt.plot([-3, -3], [0, v1], 'r--')
plt.plot([3, 3], [0, v2], 'r--')

#
plt.annotate('t1', xy=(-3, 0), xytext=(-3.1, -1))  
plt.annotate('t2', xy=(3, 0), xytext=(2.9, -1))  

plt.annotate('v1', xy=(-3, v1), xycoords='data', 
             xytext=(+10, +30), textcoords='offset points', 
             fontsize=12, arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2"))  
plt.annotate('v2', xy=(3, v2), xycoords='data', 
             xytext=(+10, +30), textcoords='offset points', 
             fontsize=12, arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2"))  
               

plt.show()


 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值