Skip to content

Commit

Permalink
[bug fixes] fixes example in gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
whitetuft committed Apr 30, 2024
1 parent b6513a9 commit 206a372
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions docs/script_examples/plot_atmosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ def tick_function(x):
return ["%.1f" % z for z in v]


def tick_function_pressure(x):
v = height_to_pressure(x * 1000)
return ["%.1f" % z for z in v]
def tick_function_pressure(p, z, ticks):
values = []
for tick in ticks:
v = p[np.where(z==tick)]
values.append(v[0])
return values


z, p, d, t, md = atmp.gl_atm(atmp.US_STANDARD)
Expand All @@ -37,14 +40,11 @@ def tick_function_pressure(x):
fig, ax = plt.subplots(1, 2, figsize=(12, 12))
ax1 = ax[0].twiny()

# ax[1].invert_yaxis()
ax[1].yaxis.set_label_position("right")
ax[1].yaxis.tick_right()
# ax[1].set_yscale('log')
ax[1].yaxis.set_major_formatter(ScalarFormatter())
ax[1].yaxis.set_major_formatter(ticker.FuncFormatter(lambda y, _: '{:g}'.format(y)))

# Add some extra space for the second axis at the bottom
fig.subplots_adjust(bottom=0.2)

ax[0].plot(t, z)
Expand All @@ -54,8 +54,8 @@ def tick_function_pressure(x):
ax[1].axes.get_yaxis().set_visible(False)
ax[0].set_ylabel("Altitude [km]")

new_tick_locations_pressure = np.arange(0, 120, 10)

new_tick_locations_pressure = np.arange(0, 140, 20)
print(ax[0])
ax3 = ax[0].twinx()
rspine = ax3.spines['left'].set_position(('axes', -0.2))
ax3.yaxis.set_ticks_position("left")
Expand All @@ -64,20 +64,16 @@ def tick_function_pressure(x):
ax3.patch.set_visible(False)
ax3.set_ylabel('Pressure [hPa]')
ax3.set_yticks(new_tick_locations_pressure)
ax3.set_yticklabels(tick_function_pressure(new_tick_locations_pressure))
ax3.set_yticklabels(tick_function_pressure(p, z, new_tick_locations_pressure))
ax3.set_ylim(ax[1].get_ylim())

new_tick_locations = np.arange(175, 400, 50)

# Move twinned axis ticks and label from top to bottom
ax1.xaxis.set_ticks_position("bottom")
ax1.xaxis.set_label_position("bottom")

# Offset the twin axis below the host
ax1.spines["bottom"].set_position(("axes", -0.1))

# Turn on the frame for the twin axis, but then hide all
# but the bottom spine
ax1.set_frame_on(True)
ax1.patch.set_visible(False)

Expand All @@ -86,10 +82,5 @@ def tick_function_pressure(x):
ax1.set_xticks(new_tick_locations)
ax1.set_xticklabels(tick_function(new_tick_locations))
ax1.set_xlabel("Temperature [°C]")
# ax1.spines['bottom'].set_position(('outward', 36))
ax1.set_xlim(ax[0].get_xlim())

# ax[0].set_ylim([0, ax[0].get_ylim()[1]])
# ax[1].set_ylim([ax[1].get_ylim()[0], 0.001])

fig.tight_layout()

0 comments on commit 206a372

Please sign in to comment.