matplotlib 画图 华氏度-摄氏度转化

转自:http://www.oschina.net/code/snippet_1174881_24083

#
!/usr/bin/python # -*- coding: UTF-8 -*- # -*- coding: utf-8 -*- """ Created on Sat Aug 24 15:46:11 2013 @author: wangxiaotao """ import numpy as np import matplotlib.pyplot as plt import matplotlib F = np.arange(-50, 240, 0.1) print F C = (F - 32)/1.8 # Basic plt.plot(F, C, 'r-', linewidth =1 ) #线宽linewidth=1 plt.title('Convert the unit of temperature') # Revise, ticks ax = plt.gca() #返回轴的实例,用来控制轴属性或使用 ax.spines['right'].set_color('none') #清楚图右边的线 ax.spines['top'].set_color('none')#清除图顶边的线 ax.xaxis.set_ticks_position('bottom') #axis坐标轴, 清除x轴坐标 ax.spines['bottom'].set_position(('data',0))#设置x轴线的位置为0 ax.yaxis.set_ticks_position('left')#清除y轴坐标 ax.spines['left'].set_position(('data',0))#设置y轴线的位置 ax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(20))#设置主要坐标定位器,间隔20 ax.xaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(2))#设置次要坐标定位器,间隔2 ax.yaxis.set_major_locator(matplotlib.ticker.MultipleLocator(20)) ax.xaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(2)) plt.grid(b=True)#显示网格plt.grid(True) sc = np.array([-40, -20, 0, 20, 37, 60, 80, 100]) sf = np.array([-40, 0, 32, 80, 37*1.8+32, 140, 180, 100*1.8+32]) plt.yticks(sc) #设置y坐标 plt.xticks(sf) # Label the specific temperatures 标记特殊点 plt.scatter([32, ], [0, ], 50, color = 'blue') plt.plot([0, 37*1.8+32], [37, 37], color = 'blue', linewidth = 2.5, linestyle = '--') plt.plot([37*1.8+32, 37*1.8+32], [0, 37], color = 'blue', linewidth = 2.5, linestyle = '--') plt.scatter([37*1.8+32, ], [37, ], 50, color = 'blue') plt.plot([0, 100*1.8+32], [100, 100], color = 'blue', linewidth = 2.5, linestyle = '--') plt.plot([100*1.8+32, 100*1.8+32], [0, 100], color = 'blue', linewidth = 2.5, linestyle = '--') plt.scatter([100*1.8+32, ], [100, ], 50, color = 'blue') plt.xlabel('Fahrenheit') plt.ylabel('Centigrade') plt.savefig('FtoC.png') #保存图片 plt.show()#显示画图结果 plt.close()

 

转载于:https://www.cnblogs.com/silencekt/p/3293071.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值