转自: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()