头文件:
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import host_subplot
import mpl_toolkits.axisartist as AA
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['FangSong']
mpl.rcParams['axes.unicode_minus'] = False
直方图绘制:
示例代码:
labels = ['Negative ID', 'Positive ID', 'Unverified', 'Unprocessed'];
# quants = [len(dN), len(dP), len(dUv), len(dUp)];
quants = [len(dNt), len(dPt), len(dUvt), len(dUpt)];
fig, ax = plt.subplots();
x = range(len(labels));
ax.bar(x,quants,0.4,color='green');
ax.set_xticks(x);
ax.set_yticks(range(0,3501,500));
ax.set_xticklabels(labels);
ax.set_ylabel('Witness number',size=14);
ax.set_title('Data analysis ', bbox={'facecolor':'0.9', 'pad':8})
# plt.grid(True)
xticks = ax.get_xticks()
for i in range(len(quants)):
xy = (xticks[i], quants[i] * 1.03)
s = str(quants[i])
ax.annotate(
s=s, # 要添加的文本
xy=xy, # 将文本添加到哪个位置
fontsize=12, # 标签大小
color="black", # 标签颜色
ha="center", # 水平对齐
va="baseline" # 垂直对齐
)
plt.savefig('dataclass_ori.png',dpi=720, bbox_inches='tight');
散点图绘制:
示例代码:
plt.title(r'$\mathrm{2020 \; nest \; distribution \; by \; K=20}\/\/$',size=25);
plt.scatter(kmd[:,0],kmd[:,1],20,c=y_predict,alpha=0.6)
plt.scatter(x,y,25,marker='*',color = 'red',alpha=0.8,label='nest orientation');
plt.legend(loc = 'best');
plt.xlabel(r'$\mathrm{Longitude}\/\/$',size=15);
plt.ylabel(r'$\mathrm{Latitude}\/\/$',size=15);
plt.ylim(45.0, 49.5)
plt.xlim(-126.0, -116.0)
plt.yticks(np.linspace(45.0, 49.5, 10))
plt.xticks(np.linspace(-126.0, -116.0,11))
plt.savefig('2020_K412.png',dpi=1080, bbox_inches='tight');
plt.show();
散点迁徙绘制:
colors:
colors = mpl.colors.TABLEAU_COLORS
colors = list(colors.values());
示例代码:
ol = -124;
oh = -123;
al = 48;
ah = 49;
ph = 30/111;
Dd20_8,la20_8,lo20_8 = DtoA(Search(ol,oh,al,ah,d20_8));
# plt.figure(dpi=300,figsize=(24,8))
fig, ax = plt.subplots();
for i in range(len(lo20_8)):
xn,yn = trans1(Sow(lo20_8[i],la20_8[i],20));
#绘制圆形
draw_circle = plt.Circle((lo20_8[i],la20_8[i]), ph,color = colors[i],alpha=0.1);
#使坐标轴比例保持圆形为正圆
ax.set_aspect(1);
ax.add_artist(draw_circle);
#绘制散点
ax.scatter(lo20_8[i],la20_8[i],45,marker='*',color = colors[i],alpha=1);
ax.scatter(xn,yn,35,marker='o',color = colors[i],alpha=1);
#绘制指向箭头
for j in range(len(xn)):
ax.annotate('', xy=(xn[j],yn[j]), xytext=(lo20_8[i],la20_8[i]), arrowprops=dict(arrowstyle="->", color=colors[i]))
#设置xy轴坐标
plt.title(r'$\mathrm{local \; nest \; spreading \; simulation}\/\/$',size=25);
plt.xlabel(r'$\mathrm{Longitude}\/\/$',size=15);
plt.ylabel(r'$\mathrm{Latitude}\/\/$',size=15);
t3 = round(ol,3);
t4 = round(oh+ph,3);
t1 = round(al-ph,3);
t2 = round(ah,3);
plt.ylim(t1,t2);
plt.xlim(t3,t4);
plt.yticks(np.linspace(t1,t2, 8))
plt.xticks(np.linspace(t3,t4, 8))
plt.savefig('Sow1tt.png',dpi=1080, bbox_inches='tight');
plt.show()