# Download and parse all the 1D models.
ak135f = get_model("http://ds.iris.edu/media/product/emc-syngine/files/1dmodel_ak135f.txt")
prem = get_model("http://ds.iris.edu/media/product/emc-syngine/files/1dmodel_PREMiso.txt")
iasp91 = get_model("http://ds.iris.edu/media/product/emc-syngine/files/1dmodel_iasp91.txt")
# Plotting everything.
fig = plt.figure(figsize=(4, 6))
gs1 = gridspec.GridSpec(1, 2, wspace=.05, hspace=0.05, left=0.15, right=0.85, bottom=0.08, top=0.98)
ax1 = fig.add_subplot(gs1[0])
ax2 = fig.add_subplot(gs1[1])
plt.sca(ax1)
plt.plot(ak135f.v_p, ak135f.depth, color="0.0", ls="-", lw=2, label="ak135-F")
plt.plot(ak135f.v_s, ak135f.depth, color="0.0", ls="-", lw=2, label="_nolegend_")
l = plt.plot(iasp91.v_p, iasp91.depth, color="0.4", ls="--", lw=2, label="iasp91")
l[0].set_dashes([5, 1])
l = plt.plot(iasp91.v_s, iasp91.depth, color="0.4", ls="--", lw=2, label="_nolegend_")
l[0].set_dashes([5, 1])
l = plt.plot(prem.v_p, prem.depth, color="0.6", ls=":", lw=2, label="PREM")
l[0].set_dashes([1, 1])
l = plt.plot(prem.v_s, prem.depth, color="0.6", ls=":", lw=2, label="_nolegend_")
l[0].set_dashes([1, 1])
plt.ylabel("Depth [km]")
plt.xlabel("Velocity [km/s]")
plt.xticks([0, 2, 4, 6, 8, 10, 12])
plt.ylim(-100, 6371)
plt.xlim(-0.5, 14)
plt.gca().invert_yaxis()
plt.sca(ax2)
plt.plot(ak135f.v_p, ak135f.depth, color="0.0", ls="-", lw=2, label="ak135-f")
plt.plot(ak135f.v_s, ak135f.depth, color="0.0", ls="-", lw=2, label="_nolegend_")
l = plt.plot(iasp91.v_p, iasp91.depth, color="0.4", ls="--", lw=2, label="iasp91")
l[0].set_dashes([5, 1])
l = plt.plot(iasp91.v_s, iasp91.depth, color="0.4", ls="--", lw=2, label="_nolegend_")
l[0].set_dashes([5, 1])
l = plt.plot(prem.v_p, prem.depth, color="0.6", ls=":", lw=2, label="PREM")
l[0].set_dashes([1, 1])
l = plt.plot(prem.v_s, prem.depth, color="0.6", ls=":", lw=2, label="_nolegend_")
l[0].set_dashes([1, 1])
ax2.yaxis.tick_right()
ax2.yaxis.set_label_position("right")
plt.ylabel("Depth [km]")
plt.xlabel("Velocity [km/s]")
plt.xticks([0, 2, 4, 6, 8])
plt.ylim(-.784806153, 50)
plt.xlim(2.7, 8.5)
plt.gca().invert_yaxis()
legend = plt.legend(loc="lower left", fancybox=True, frameon=True)
plt.savefig("earth_models.pdf")
plt.show()