python的matplotlib库总结

1、x=np.linspace(0,10,100) 生成array([0,10,20,30...,110])(包含初始值和结束值)

2、简单的例子

把绘图窗口分成两行两列四块区域,然后在每个区域分别作图,基本步骤:

subplot(2,2,1); % 221之间没有逗号也可以

在第一块绘图

subplot(2,2,2);

在第二块绘图

subplot(2,2,3);

在第三块绘图

subplot(2,2,4);

在第四块绘图

3ctrl+shift+F10 快速运行当前脚本

4、对函数与坐标轴之间的区域进行填充,使用fill函数

填充两个函数之间的区域,使用fill_between函数

 

5、区别。画一个图和画两个图之间函数的差别。

plt.xlabel() ax.set_xlabel()

plt.ylabel() ax.set_ylabel()

plt.xlim() ax.set_xlim()

plt.ylim() ax.set_ylim()

plt.title() ax.set_title()

ax.set(xlim=(0,10),ylim=(),xlabel=,title=)

6

rng = numpy.random.RandomState(23355)

arrayA = rng.uniform(0,1,(2,3))

  

该段代码的目的是产生一个23列的assarray,其中的每个元素都是[0,1]区间的均匀分布的随机数

这里看以看到,有一个23355这个数字,其实,它是伪随机数产生器的种子,也就是“the starting point for a sequence of pseudorandom number”

对于某一个伪随机数发生器,只要该种子(seed)相同,产生的随机数序列就是相同的

rng = numpy.random.RandomState(0)

rng.rand(5)

随机产生50,1之间的均匀分布的随机数。

7、少用subplots,subplot,MATLAB那样去编程。

8

for marker in ['o','.',',','x','+','v','^','<','>','s','d']:

      plt.plot(rng.rand(5),rng.rand(5),marker,       label="marker={0}".format(marker),markersize=15,

markerfacecolor='white',markeredgewidth=2,

      markeredgecolor=(0,0,0.4,0.1))

      plt.legend(numpoints=1)

      plt.xlim(0,1.8)

format(marker)里面的marker指的是变量marker!!!

9cyan是青色的意思

‘--c’绘制青色线条。

10、

https://www.cnblogs.com/wj-1314/p/8490822.html

多用迭代器,少用列表,(前提是你迭代器弄得很会,yield迭代器占用内存更少)

11、

如何输出合并单元格的内容

>>> merge = []

>>> for (rlow,rhigh,clow,chigh) in sheet2.merged_cells:

...   merge.append([rlow,clow])

...>>> merge

[[1, 4], [3, 4], [5, 1]]

>>> for index in merge:

...   print sheet2.cell_value(index[0],index[1])

...

friend

friend2

None

 

12、

from matplotlib.font_manager import *


myfont =

FontProperties(fname='D:\Python\Lib\site-packages\matplotlib\mpl-data/fonts/ttf/arcdps_font.ttf')
mpl.rcParams['axes.unicode_minus']=False

plt.xlabel('年份',fontproperties=myfont)
plt.ylabel('低保数额(元)',fontproperties=myfont)

plt.legend(prop =myfont)

 

解决字体问题

13、

print(df.sum(axis=1)),数组内部相加,总个数为数组个数。

print(df.sum(axis=0)),数组对应位置数字相加,总个数为单个数组中数字的个数。

 

14、

matplotlib.rcParams['font.sans-serif'] = ['SimHei']

matplotlib.rcParams['axes.unicode_minus'] = False

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值