matplotlib画图
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x = np.arange(-10,11)
plt.plot(x,x**2)
``
调整坐标范围
方法1:plt.axis([-5,5,0,10])
方法2:plt.xlim(-5,5)
改变坐标轴刻度数
ax = plt.gca()
ax.locator_params(‘x’,nbins=5)
添加坐标轴
x = np.arange(2,20)
y1 = x*x
y2 = np.log(x)
plt.plot(x,y1)
plt.twinx()
plt.plot(x,y2)
方法2
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot(x,y1,label=‘y1’)
ax.set_ylabel(‘y1’)
ax.legend()
ax2 = ax.twinx()
ax2.plot(x,y2,color=‘r’,label=‘y2’)
ax2.set_ylabel(‘y2’)
ax2.legend(loc=0)
``