我有一个 DataFrame,其列 ['country', 'year', 'population'] 显示在散点图上。每个国家一个点,x 轴为年份,y 轴为 y。
每当鼠标悬停在一个点上时,我想使用 ipwidgets(严格要求)来显示国家名称、年份和人口。
它不必在图表上,但如果它是很好的。我正在使用 jupyter-notebook。
作为最小的示例,您可以使用:
import pandas as pd
import io
import matplotlib.pyplot as plt
%matplotlib inline
df = pd.read_csv(io.StringIO('''Country,Year,Population
India,1950,357561
India,2000,1008937
India,2015,1230484
India,2025,1351801
India,2050,1572055
China,1950,554760
China,2000,1275133
China,2015,1410217
China,2025,1470787
China,2050,1462058
USA,1950,157813
USA,2000,283230
USA,2015,321225
USA,2025,346822
USA,2050,397063'''), sep=',')
plt.scatter(df['Year'], df['Population'])