matplotlib画图基础,华氏温度到摄氏温度的转换
来源:互联网 发布:java const 编辑:程序博客网 时间:2024/05/22 10:39
由于fedora19默认安装的weather app不能显示摄氏温度,想到要画这么张图。此代码中涉及基本的plot、 scatter函数,坐标轴的控制等内容。
1、代码
# -*- coding: utf-8 -*-"""Created on Sat Aug 24 15:46:11 2013@author: wangxiaotao"""import numpy as npimport matplotlib.pyplot as pltimport matplotlibF = np.arange(-50, 240, 0.1)C = (F - 32)/1.8# Basicplt.plot(F, C, 'r-', linewidth = 0.5)plt.title('Convert the unit of temperature')# Revise, ticksax = plt.gca()ax.spines['right'].set_color('none')ax.spines['top'].set_color('none')ax.xaxis.set_ticks_position('bottom')ax.spines['bottom'].set_position(('data',0))ax.yaxis.set_ticks_position('left')ax.spines['left'].set_position(('data',0))ax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(20))ax.xaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(2))ax.yaxis.set_major_locator(matplotlib.ticker.MultipleLocator(20))ax.xaxis.set_minor_locator(matplotlib.ticker.MultipleLocator(2))plt.grid(b = 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); plt.xticks(sf)# Label the specific temperaturesplt.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.close()
2. [图片] FtoC.png
转自:http://www.oschina.net/code/snippet_1174881_24083
- matplotlib画图基础,华氏温度到摄氏温度的转换
- 摄氏温度 华氏温度 的转换
- 摄氏温度和华氏温度的转换
- 华氏温度与摄氏温度的转换
- 实现摄氏温度与华氏温度的转换
- 实现摄氏温度与华氏温度之间的转换
- 实现华氏温度与摄氏温度的转换
- 实现摄氏温度和华氏温度的相互转换
- 华氏温度转换成摄氏温度的程序
- 华氏温度转换摄氏温度程序
- 摄氏温度和华氏温度转换
- 摄氏温度转换华氏温度
- 摄氏温度转换华氏温度
- C语言基础 将摄氏温度转换为华氏温度
- 摄氏温度和华氏温度转换改进
- 将摄氏温度转换为华氏温度
- C++华氏温度和摄氏温度转换
- 将摄氏温度转换成华氏温度
- 结婚是人生中最重要的事情之一:请看五个经典浪漫的婚宴形式
- 模拟lastlog程序
- Android 蓝牙开发详述
- std::auto_ptr
- 派生类的基本函数的实现
- matplotlib画图基础,华氏温度到摄氏温度的转换
- 如何使用PC/SC非接触读卡器获取13.56M卡片UID以及ATS
- &分享两妙方 帮你打开win7重装后的文件夹&【386w】
- Cisco(思科)交换机VLAN设置(转自磊哥方法)
- Mailcore 2: Introduction
- ※数据结构※→☆线性表结构(list)☆============单向链表 链式存储结构(list single)(二)
- java中导入导出Excel表格(jxl的API应用)
- 2013年的目标
- havlenapetr大牛的工程,是可以直接编译过的