# ältere Bibliothek
# - statische Plots
import matplotlib.pyplot as plt
import pandas as pd

# interaktion
# import plotly


# plotten direkt von pandas
#  -> backend: matplotlib


cities = {"Stadt": ["London", "Berlin", "Madrid", "Rom",
                   "Paris", "Wien", "Bukarest", "Hamburg",
                   "Budapest", "Warsaw", "Barcelona",
                   "München", "Mailand"],
          "Population": [8615246, 3562166, 3165235, 2874038,
                         2273305, 1805681, 1803425, 1760433,
                         1754000, 1740119, 1602386, 1493900,
                         1350680],
          "Land": ["England", "Deutschland", "Spanien", "Italien",
                      "Frankreich", "Österreich", "Romanien",
                      "Deutschland", "Ungarn", "Polen", "Spanien",
                      "Deutschland", "Italien"]}

areas = [1572, 892, 604,  1285, 105,415, 228, 755, 525, 517, 101, 310, 182]
cities_df = pd.DataFrame(cities)
cities_df["Flaeche"] = areas
print(cities_df)

#cities_df.plot(x="Stadt", y=["Population", "Flaeche"])
#plt.xticks(range(len(cities_df)), cities_df["Stadt"], rotation=70)
#plt.show()

fig, ax = plt.subplots()
cities_df.plot(x="Stadt", y=["Population", "Flaeche"], ax=ax)
ax.set_xticks(range(len(cities_df)), cities_df["Stadt"], rotation=70)
fig.suptitle("Area und Flaeche in einem")

fig, ax = plt.subplots(2, 1, sharex=True)  # ax ein array mit 2 elementen
cities_df.plot(x="Stadt", y="Population", ax=ax[0])
cities_df.plot(x="Stadt", y="Flaeche", ax=ax[1])
fig.suptitle("2 axes in einer figure")
for i in range(2):
    ax[i].set_xticks(range(len(cities_df)), cities_df["Stadt"], rotation=70)

fig, ax = plt.subplots()

area_axes = ax.twinx()

width = 0.35

x_pos = range(len(cities_df))  # 0, 1, 2, ..., 12
ax.bar([x - width/2 for x in x_pos], cities_df["Population"], width=width, color="blue", label="Population")
area_axes.bar([x + width/2 for x in x_pos], cities_df["Flaeche"], width=width, color="orange", label="Flaeche")

ax.set_xticks(range(len(cities_df)), cities_df["Stadt"], rotation=70)
fig.suptitle("Area und Flaeche in einem")
handles1, labels1 = ax.get_legend_handles_labels()
handles2, labels2 = area_axes.get_legend_handles_labels()

ax.legend(handles1 + handles2, labels1 + labels2)

plt.show()





