matplotlib画图

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)
``
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值