Соедините точки данных в линейной диаграмме в Python - PullRequest
0 голосов
/ 15 ноября 2018

Я определил эту функцию в Python для отображения двух индикаторов gini и economic freedom с течением времени.

def PlotCountry(countries):
    simple = df_gini.loc[countries, :].sort_values(by = "year", ascending = True)
    simple = simple.reset_index()
    simple = simple.drop(['rank', '5_regulation'], axis = 1)
    simple = simple.round(2)
    simple.columns = ["Year", "ISO Code", "Gini Index", "Economic Freedom"]

    #Plot a double-axis lineplot
    fig, ax1 = plt.subplots()
    color = 'darkred'
    ax1.set_xlabel('Year')
    ax1.set_ylabel('Gini Index', color = color)
    ax1.plot("Year", "Gini Index", color = color, data = simple, linestyle='--', marker = ".")
    ax1.tick_params(axis='y', labelcolor = color)

    ax2 = ax1.twinx()  #Instantiate second axis that shares the same x-axis

    color = 'darkblue'
    ax2.set_ylabel('Economic Freedom', color = color)
    ax2.plot("Year", "Economic Freedom", color = color, data = simple)
    ax2.tick_params(axis='y', labelcolor=color)

    plt.title(countries)

    fig.tight_layout()  #Otherwise right y-label is slightly clipped
    plt.show()

Иногда сюжет, который я получаю, выглядит так: enter image description here

Как мне соединить красные точки?

...