效果图:

import matplotlib.pyplot as plt

import numpy as np

x = np.linspace(-100,100,100)

y = x**3

plt.figure(num=3,figsize=(8,5))   #num xuhao;figsize long width

l1=plt.plot(x,y,'p')  # quta is to return name to plt.legend(handles)

plt.xlim((-100,100))

plt.ylim((-100000,100000))

plt.xlabel('X')   #x zhou label

plt.ylabel('Y')

ax = plt.gca()

ax.spines['right'].set_color('none')

ax.spines['top'].set_color('none')    ##don't display border

ax.xaxis.set_ticks_position('bottom')    ##set x zhou

ax.yaxis.set_ticks_position('left')

ax.spines['bottom'].set_position(('data',0))  #y 0 postition is x position

ax.spines['left'].set_position(('data',0))

###tu li

# labels can just set one label just post one line

plt.legend(handles=l1,labels='y=x**3',loc='best')  ##loc=location

plt.show()


效果图:

wKioL1jI3y-jTBeJAABLoHSPzSI134.png-wh_50