Created
October 7, 2022 19:28
-
-
Save hbshrestha/49107988c26fc3f6054280d16b2812da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rescale = lambda y: (y - np.min(y)) / (np.max(y) - np.min(y)) | |
fig, ax1 = plt.subplots() | |
x = df_temp.index.tolist() | |
y = df_temp["mean"].values.tolist() | |
ax1.bar(x, y, color = my_cmap(rescale(y)), width = 0.8) | |
ax1.set_ylabel("Temperature anomaly \n relative to 1951-80 mean (°C)", color = "red") | |
ax1.tick_params(axis='y', color='red', labelcolor='red') | |
ax1.grid(False) | |
#Add twin axes | |
ax2 = ax1.twinx() | |
ax2.plot(co2_annual, color = "black", marker = "o", markersize = 4) | |
ax2.set_ylabel("CO$_2$ (ppm)") | |
ax2.grid(False) | |
ax2.tick_params(axis='y') | |
for pos in ["top"]: | |
ax1.spines[pos].set_visible(False) | |
ax2.spines[pos].set_visible(False) | |
plt.grid() | |
plt.title("Global temperature anomaly and atmospheric CO$_2$ emissions concentration\n (1959-2021)", | |
pad = 20) | |
plt.savefig("../output/co2 emissions and temperature anomalies bar plot.jpeg", | |
dpi = 300) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment