0
votes

I have two questions, 1, I want to modify the space between the title and plot; 2, I do not know how to specify a font style and size of colobar tick in the subplot; It demand me to post more detail about my quesiton, I do not know what I should I provide. so better to ask a quesion. Why is it very slow when I add the save: plt.savefig("Fig01.png",dpi=1000, bbox_inches='tight') It will cost many time to save, and I can not get the pdf version. I do not why. and I think the color in my plot is not so good. where can I find more color?

[![results][1]][1]




import matplotlib
import matplotlib.pyplot as plt
import numpy as np

a1,b1,c1 = np.loadtxt("00_porostiy.txt", unpack=True)
a2,b2,c2 = np.loadtxt("04_porostiy.txt", unpack=True)
a3,b3,c3 = np.loadtxt("04_00_porostiy.txt", unpack=True)

x1=a1.reshape(51,16)
y1=b1.reshape(51,16)
z1=c1.reshape(51,16)

x2=a2.reshape(51,16)
y2=b2.reshape(51,16)
z2=c2.reshape(51,16)

x3=a3.reshape(51,16)
y3=b3.reshape(51,16)
z3=c3.reshape(51,16)

fig, (ax1,ax2,ax3) = plt.subplots(figsize=(12,8), ncols=3)

cet1=ax1.contourf(x1, y1, z1, 100, cmap="jet")
#依据第一个txt文件里的数据绘图,平滑等级100,上色为jet
ax1.set_aspect(aspect=1)
#强制x与y按照1:1
ax1.set_title("Initial", fontname='Helvetica', fontsize = 12)
#设置顶部文字
cet1_bar=fig.colorbar(cet1, ax=ax1, aspect=60)
#在图1旁边绘制图例,图例调窄,调窄因子为80
cet1_bar.outline.set_visible(False)
#图例中黑色边框去掉
#ax1.tick_params(axis='both', which='major', labelsize=12)
ax1.set_xticks([0,2.5,5])
plt.setp(ax1.get_xticklabels(), fontsize=12, fontname="Times New Roman")
plt.setp(ax1.get_yticklabels(), fontsize=12, fontname="Times New Roman")

cet2=ax2.contourf(x2, y2, z2, 100, cmap="jet")
ax2.set_title("10 000 years", fontname='Helvetica', fontsize = 12)
cet2_bar=fig.colorbar(cet2, ax=ax2, aspect=60)
ax2.set_aspect(aspect=1)
cet2_bar.outline.set_visible(False)
ax2.set_xticks([0,2.5,5])
plt.setp(ax2.get_xticklabels(), fontsize=12, fontname="Times New Roman")
plt.setp(ax2.get_yticklabels(), fontsize=12, fontname="Times New Roman")

cet3=ax3.contourf(x3, y3, z3, 100, cmap="jet")
ax3.set_title("Change", fontname='Helvetica', fontweight='bold')
cet3_bar=fig.colorbar(cet3, ax=ax3, aspect=60) 
ax3.set_aspect(aspect=1)
cet3_bar.outline.set_visible(False)
ax3.set_xticks([0,2.5,5])
plt.setp(ax3.get_xticklabels(), fontsize=12, fontname="Times New Roman")
plt.setp(ax3.get_yticklabels(), fontsize=12, fontname="Times New Roman")
plt.subplots_adjust(bottom=0.1, wspace=0.01) #好像不起作用

plt.savefig("Fig01.png",dpi=1000, bbox_inches='tight')
plt.show()
1

1 Answers

0
votes
  1. In your statement, add 'pad' to increase the space between plot and title:

    ax1.set_title("Initial", fontname='Helvetica', fontsize = 12, pad=10)