Python有用知识点

记录python一些有用的方法,不定期更新

判断字典里是否含有某键

Python 3.X 里不包含 has_key() 函数,被 contains(key) 替代:

dict3 = {'name':'z','Age':7,'class':'First'};
print("Value : ",dict3.__contains__('name'))
print("Value : ",dict3.__contains__('sex'))

执行结果:

Value :  True
Value :  False

python设置坐标轴字体大小的若干方法:

plt.xticks(fontsize= ) to Set Tick Labels Font Size
ax.set_xticklabels(xlabels, fontsize = ) #to Set Tick Labels Font Size
plt.setp(ax.get_xticklabels(), fontsize =) #to Set Tick Labels Font Size
ax.tick_params(axis = 'x', labelsize = ) #to Set Tick Labels Font Size

简单把字典存入本地并读取的方法:

#保存
dict_name = {1:{1:2,3:4},2:{3:4,4:5}}
f = open('temp.txt','w')
f.write(str(dict_name))
f.close()

#读取
f = open('temp.txt','r')
a = f.read()
dict_name = eval(a)
f.close()

查看jupyter各个变量所占内存大小:

import sys

a = %who_ls

for i in a:
    print(i,':',sys.getsizeof(i)/1024,'K')

去除画图的边框

fig, Axes = plt.subplots(1,1,figsize = (10,8))
for Key in list(P.keys())[:4]:
    Axes.plot(x,P[Key],label = Key)
    Axes.spines['top'].set_visible(False)
    Axes.spines['right'].set_visible(False)
    Axes.text(x[-1], P[Key][-1], Key, fontsize=15)

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值