matplotlib基础知识

STSong最像中文宋体,西文新罗马的字体

plt.rcParams['font.sans-serif']=['STSong']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False  # 用来正常显示负号
plt.rcParams['font.size']=14#设置全局字体

matplotlib保存图片不完整

以以下代码保存即可

fig.savefig(r'C:\Users\mxs\Desktop\大论文相关材料\大论文插图\discrete.png',dpi=400,bbox_inches = 'tight')

新罗马字体太粗

import matplotlib.font_manager as mpf
del mpf.weight_dict['roman']
mpf._rebuild()

设置坐标轴刻度间隔

from matplotlib.pyplot import MultipleLocator
y_major_locator=MultipleLocator(1)#把y轴的刻度间隔设置为1,并存在变量里
ax1.yaxis.set_major_locator(y_major_locator)#把y轴的主刻度设置为1的倍数  

设置坐标轴刻度范围

plt.xlim((start,stop))
plt.ylim((start,stop))

ax.xlim((start,stop))
ax.ylim((start,stop))

pyhton逆序切片

a=[[12,3,3],[2,3,4],[3,4,5]]
a[:-len(a):-1]

colorbar字体大小

cb=plt.colorbar(b)
cb.ax.tick_params(labelsize=14)  #设置色标刻度字体大小。

坐标轴刻度字体

plt.rcParams["font.sans-serif"] = ["Times New Roman"]
plt.rcParams['xtick.labelsize']=14
plt.rcParams["axes.unicode_minus"] = False
labels = ax.get_xticklabels() + ax.get_yticklabels()
[label.set_fontname('Times New Roman') for label in labels]

plt.figure(figsize=[15,8]) 
plt.scatter(X, Y, label = 'RealValue')
plt.plot(X, func(X, a, b), 'red', label = 'CurveLine') 
plt.title(station, fontdict={'family' : 'Times New Roman', 'size' : 16})
plt.ylabel('Clocks($\mu S$)', fontdict={'family' : 'Times New Roman', 'size' : 16})
plt.xlabel('Time', fontdict={'family' : 'Times New Roman', 'size' : 16})
plt.yticks(fontproperties = 'Times New Roman', size = 14) 
plt.xticks(fontproperties = 'Times New Roman', size = 14) 
plt.legend(prop={'family' : 'Times New Roman', 'size' : 16})
plt.savefig('./stationClocks/' + station + '.ps', dpi = 200) 
plt.show()

matplotlib添加坐标轴

%matplotlib auto
import matplotlib.pyplot as plt
from pylab import *
x = linspace(0, 5, 10)
y = x ** 2

fig = plt.figure()

axes = fig.add_axes([0.2, 0.2, 0.5, 0.5]) # left, bottom, width, height (range 0 to 1)
axes2 = fig.add_axes([0.2, 0.5, 0.4, 0.3]) # inset axes

axes.plot(x, y, 'r')

axes.set_xlabel('x')
axes.set_ylabel('y')
axes.set_title('title')

# insert
axes2.plot(y, x, 'g')
axes2.set_xlabel('y')
axes2.set_ylabel('x')
axes2.set_title('insert title');

plt.show()

Jupyter–matplolib弹窗绘图与内嵌绘图

%matplotlib inline
%matplotlib auto
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小孟的CDN

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值