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