python设置标题、轴标签、刻度标签(ticker部分)
import numpy as np
import matplotlib.pyplot as plt
plt.figure()
x = np.arange(0,10,1)
z = x**2
y = np.linspace(1,10,10)
plt.plot(x,z,color = 'red',linewidth=1.0,linestyle='--')
plt.title(u'方法一')
plt.xlabel('X')
plt.ylabel('Y')
plt.xlim(0,10)
plt.ylim(0,100)
plt.xticks([0,1,2,3,4,5,6,7,8,9,10])
plt.yticks([0, 20, 60, 80, 100],
[r'$really\ bad$', r'$bad$', r'$normal$', r'$good$', r'$readly\ good$'])
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax = plt.gca()
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.spines['bottom'].set_position(('data', 10))
ax.spines['left'].set_position(('data', 2))
plt.show()
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0,10,1)
z = x**2
ax = plt.subplot()
ax.plot(x,z)
ax.set_xlim(0,10)
ax.set_ylim(0,100)
ax.set_title(u'方法二')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_yticks([0,10,20,50,100])
ax.set_yticklabels(('one','two','three', 'four', 'five'))
plt.show()
from pylab import *
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
xmajorLocator = MultipleLocator(20)
xmajorFormatter = FormatStrFormatter('%1.1f')
xminorLocator = MultipleLocator(5)
ymajorLocator = MultipleLocator(0.5)
ymajorFormatter = FormatStrFormatter('%1.1f')
yminorLocator = MultipleLocator(0.1)
t = arange(0.0, 100.0, 1)
s = sin(0.1*pi*t)*exp(-t*0.01)
ax = subplot(111)
plot(t,s,'--b*')
ax.xaxis.set_major_locator(xmajorLocator)
ax.xaxis.set_major_formatter(xmajorFormatter)
ax.yaxis.set_major_locator(ymajorLocator)
ax.yaxis.set_major_formatter(ymajorFormatter)
ax.xaxis.set_minor_locator(xminorLocator)
ax.yaxis.set_minor_locator(yminorLocator)
ax.xaxis.grid(True, which='major')
ax.yaxis.grid(True, which='minor')
show()