Как показать метку, когда я щелкаю серию на графике в Python - PullRequest
0 голосов
/ 19 сентября 2019

Мне нужно показать, какую серию линия показала на графиках с множеством линий.

У меня есть серия многих стран с множеством макроэкономических рядов.

Если вы видите по ссылке , на моем графике много серий, и я не вижу разницы между одной и той же серией для всех стран.Я хочу видеть, когда я щелкаю по любой строке, чтобы узнать, какая страна.

Это мой код:

Database.set_index('Year', inplace = True)
fig = plt.figure(figsize=(16,9))
plt.legend()
plt.tight_layout()
plt.subplots_adjust(left  = 0.125,  # the left side of the subplots of the figure
right = 0.9,    # the right side of the subplots of the figure
bottom = 0.1,   # the bottom of the subplots of the figure
top = 0.9  ,    # the top of the subplots of the figure
wspace = 0.2,   # the amount of width reserved for blank space between subplots
hspace = 0.5 )  # the amount of height reserved for white space between subplots)
line_labels = ["Bolivia", "Brazil", "Chile", "Colombia",'Costa Rica','Dominican Republic',
               'Guatemala','Guyana','Jamaica', 'Mexico','Paraguay', 'Peru', 'StLucia', 'Uruguay' ]


plt.subplot(3,3,1)
#fig.ax = plt.subplots(figsize=(4,3))
GDP = Database.groupby('Countries')['GDP_Index'].plot()
plt.grid()
plt.title('GDP')

plt.subplot(3,3,2)
#fig.ax = plt.subplots(figsize=(4,3))
CPI = Database.groupby('Countries')['CPI'].plot()
plt.grid()
plt.title('CPI')

plt.subplot(3,3,3)
#fig.ax = plt.subplots(figsize=(16,9))
IR = Database.groupby('Countries')['Interest_Index'].plot()
plt.xlim([1980,2018])
plt.grid()
plt.title('Real Interest Rate')

plt.subplot(3,3,4)
#fig.ax = plt.subplots(figsize=(16,9))
GOV = Database.groupby('Countries')['Government'].plot()
plt.grid()
plt.title('Government Spend')


plt.subplot(3,3,5)
#fig.ax = plt.subplots(figsize=(16,9))
Money = Database.groupby('Countries')['Broad Money'].plot()
plt.grid()
plt.title('Broad Money(% of GDP)')

plt.subplot(3,3,6)
#fig.ax = plt.subplots(figsize=(16,9))
Trade = Database.groupby('Countries')['Trade (% of GDP)'].plot()
plt.grid()
plt.title('Trade (% of GDP)')



fig.legend([GDP, CPI, IR, GOV,Money, Trade],     # The line objects
           labels=line_labels,   # The labels for each line  
#           borderaxespad=0.1,    # Small spacing around legend box  # Title for the legend
           loc='center', 
           bbox_to_anchor=(0.4,0.16),  
           fancybox=True, framealpha=1, 
           shadow=True, borderpad=1, title= 'Countries',ncol=7)
fig.suptitle('Macroeconomic factors', fontsize=16)
#plt.subplots_adjust(right)

1 Ответ

0 голосов
/ 19 сентября 2019

Попробуйте plotly .
Plotly's Python - это графическая библиотека с открытым исходным кодом, которая создает интерактивные графики качества публикации.

Здесь - это пример, который делает именно то, что вам нужно.

...