import matplotlib.pyplot as plt
import pandas as pd
climate_change = pd.read_csv("../datasets/climate_change.csv", parse_dates=["date"], index_col=["date"])
medals = pd.read_csv("../datasets/medals_by_country_2016.csv", index_col=0)
fig, ax = plt.subplots(2, 1, sharey=True) # It shares the same y axys for both graphs
ax[0].plot(climate_change.index, climate_change["co2"])
ax[1].plot(climate_change.index, climate_change["relative_temp"])
plt.show()
def plot_timeseries(ax, x, y, color, xlabel, ylabel):
ax.plot(x, y, color=color)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel, color=color)
ax.tick_params(axis='y', colors=color)
fig, ax = plt.subplots()
plot_timeseries(ax, climate_change.index, climate_change["co2"], "blue", "Time", "CO2 (ppm)")
ax2 = ax.twinx()
plot_timeseries(ax2, climate_change.index, climate_change["relative_temp"], "red", "Time", "Relative Temperature (Celsius)")
ax2.annotate(">1 degree",
xy=(pd.Timestamp('2015-10-06'),1),
xytext=(pd.Timestamp('2008-10-06'),-0.2),
arrowprops={"arrowstyle":"->", "color":"gray"})
plt.show()
fig, ax = plt.subplots()
ax.bar(medals.index, medals["Gold"], label="Gold")
ax.bar(medals.index, medals["Silver"], bottom=medals["Gold"], label="Silver")
ax.bar(medals.index, medals["Bronze"], bottom=medals["Gold"] + medals["Silver"], label='Bronze')
ax.set_xticklabels(medals.index, rotation=90)
ax.set_ylabel("Number of medals")
ax.legend()
plt.show()
C:\Users\franc\AppData\Local\Temp\ipykernel_1016\2880509723.py:5: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator. ax.set_xticklabels(medals.index, rotation=90)
"""
fig, ax = plt.subplots()
# Plot a histogram of "Weight" for mens_rowing
ax.hist(mens_rowing["Weight"], label="Rowing", histtype="step", bins=5)
# Compare to histogram of "Weight" for mens_gymnastics
ax.hist(mens_gymnastics["Weight"], label="Gymnastics", histtype="step", bins=5)
ax.set_xlabel("Weight (kg)")
ax.set_ylabel("# of observations")
# Add the legend and show the Figure
ax.legend()
plt.show()
"""
'\nfig, ax = plt.subplots()\n\n# Plot a histogram of "Weight" for mens_rowing\nax.hist(mens_rowing["Weight"], label="Rowing", histtype="step", bins=5)\n\n# Compare to histogram of "Weight" for mens_gymnastics\nax.hist(mens_gymnastics["Weight"], label="Gymnastics", histtype="step", bins=5)\n\nax.set_xlabel("Weight (kg)")\nax.set_ylabel("# of observations")\n\n# Add the legend and show the Figure\nax.legend()\nplt.show()\n'
"""
fig, ax = plt.subplots()
# Add a boxplot for the "Height" column in the DataFrames
ax.boxplot([mens_rowing["Height"], mens_gymnastics["Height"]])
# Add x-axis tick labels:
ax.set_xticklabels(["Rowing", "Gymnastics"])
# Add a y-axis label
ax.set_ylabel("Height (cm)")
plt.show()
"""
'\nfig, ax = plt.subplots()\n\n# Add a boxplot for the "Height" column in the DataFrames\nax.boxplot([mens_rowing["Height"], mens_gymnastics["Height"]])\n\n# Add x-axis tick labels:\nax.set_xticklabels(["Rowing", "Gymnastics"])\n\n# Add a y-axis label\nax.set_ylabel("Height (cm)")\n\nplt.show()\n'
eighties = climate_change["1980-01-01":"1989-12-31"]
nineties = climate_change["1990-01-01":"1999-12-31"]
fig, ax = plt.subplots()
ax.scatter(eighties["co2"], eighties["relative_temp"], color="red", label="eighties")
ax.scatter(nineties["co2"], nineties["relative_temp"], color="blue", label="nineties")
ax.set_xlabel("CO2 (ppm)")
ax.set_ylabel("Relatiive temperature (Celsius)")
ax.legend()
plt.show()
fig, ax = plt.subplots()
ax.scatter(climate_change["co2"], climate_change["relative_temp"], c=climate_change.index)
ax.set_xlabel("CO2 (ppm)")
ax.set_ylabel("Relatiive temperature (Celsius)")
plt.show()
plt.style.use("tableau-colorblind10")
fig, ax = plt.subplots()
ax.scatter(climate_change["co2"], climate_change["relative_temp"], c=climate_change.index)
ax.set_xlabel("CO2 (ppm)")
ax.set_ylabel("Relatiive temperature (Celsius)")
plt.show()