# 1创建2个图形区域,一个叫做green,大小是16,8,一个叫做red,大小是10,6
# 2绿色区域画一条绿色的正弦曲线,红色区域化两条线,一条是绿色的正弦曲线,一条是红色的余弦曲线
# 3在green的绿色的正弦曲线上,把sin(π/6)=1/2这个公式参照课件中的标注方式进行标注
# 4坐标轴的刻度分别是x:-π,-π/2,π/2,π y:-1,-0.5,0,0.5,1
# 5坐标轴的交点要求在原点坐标,设置坐标轴,隐去右边线和上边线,将下边线和左边线设置为原点
# 6将图例设置显示并放在图形的右上方
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator # 显示中文
plt.rcParams['font.sans-serif'] = ['SimHei']
# 解决无法显示负号
plt.rcParams['axes.unicode_minus'] = False #1
plt.figure(figsize=(30,10))
rect1 = [1/30, 1/10, 16/30, 8/10] # [左, 下, 宽, 高] 规定的矩形区域 (全部是0~1之间的数,表示比例)
rect2 = [18/30, 1/10, 10/30, 6/10]
green = plt.axes(rect1)
red = plt.axes(rect2)
# plt.show() #2
x1 = np.linspace(0.0, 8.0)
x2 = np.linspace(0.0, 5.0)
x3 = np.linspace(0.0, 5.0)
y1=np.sin(x1)
y2=np.cos(x2)
y3=np.sin(x3)
green.plot(x1, y1, color='green', ms=3, label="y=sin(x)")
red.plot(x3, y3, color='green', ms=3,label="y=sin(x)")
red.plot(x2, y2, color='red', ms=3,label="y=cos(x)")
# plt.show() #3
#r'$xxxx$'
#xy=标注点位置
#xytext:描述框相对xy位置
#textcoords='offset points',以xy为原点偏移xytext
#arrowprops = 画弧线箭头,'---->', rad=.2-->0.2弧度
green.annotate(r'$sin(π/6)=1/2$',xy=(np.pi/6,1/2),xytext=(+30,-30),textcoords='offset points',fontsize=16,
arrowprops=dict(arrowstyle='->',connectionstyle='arc3,rad=.2'))
# plt.show() #4
x_major_locator=MultipleLocator(np.pi/2)
y_major_locator=MultipleLocator(1/2)
green.xaxis.set_major_locator(x_major_locator)
green.yaxis.set_major_locator(y_major_locator)
red.xaxis.set_major_locator(x_major_locator)
red.yaxis.set_major_locator(y_major_locator)
# plt.show() #5
green.spines['top'].set_visible(False)
green.spines['right'].set_visible(False)
green.spines['bottom'].set_position(('data',0))#data表示通过值来设置x轴的位置,将x轴绑定在y=0的位置
green.spines['left'].set_position(('data',0))#data表示通过值来设置y轴的位置,将y轴绑定在x=0的位置
red.spines['top'].set_visible(False)
red.spines['right'].set_visible(False)
red.spines['bottom'].set_position(('data',0))#data表示通过值来设置x轴的位置,将x轴绑定在y=0的位置
red.spines['left'].set_position(('data',0))#data表示通过值来设置y轴的位置,将y轴绑定在x=0的位置
# plt.show() #6
green.legend(loc='upper right')
red.legend(loc='upper right')
plt.show()

最新文章

  1. proj.4 线程安全
  2. js基础篇——call/apply、arguments、undefined/null
  3. 打印完整URL
  4. DOM基础3
  5. 李洪强iOS经典面试题125
  6. 151102SQL语句
  7. NGUI之自适应屏幕
  8. mybatis使用小记
  9. Asp.net项目因Session阻塞导致页面打开速度变慢
  10. [转载]新功能:用微软的Live Writer离线写博文
  11. SDUT 3346 数据结构实验之二叉树七:叶子问题
  12. Xamarin for Visual Studio 破解日志
  13. Activiti源码浅析:Activiti的活动授权机制
  14. git_share
  15. 在Mac OS X苹果lion系统上制作USB启动盘
  16. Python入门(一):PTVS写Python程序,调试模式下input()提示文字乱码问题
  17. 【安全性测试】Android测试中的一点小发现
  18. es6 箭头函数【箭头表达式】
  19. 第41章:MongoDB-集群--Sharding(分片)
  20. c++、Java、python对应的编译型语言和解释性语言区别详解

热门文章

  1. acute, adapt
  2. day11 序列化组件、批量出入、自定义分页器
  3. WebService学习总览
  4. 创建Oracle数据库实例
  5. 关于mysql自动备份的小方法
  6. Spring中的InitializingBean与DisposableBean
  7. Oracle带输入输出参数的存储过程
  8. Oracle 表结构管理
  9. MySQL 用户权限相关命令
  10. freeswitch APR库线程读写锁