文章目录
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