用户将鼠标悬停在地图上后,获取数据

时间:2019-03-10 14:12:52

标签: python geopandas

在将goepandas数据框与数字数据框合并后,我使用geopandas可视化地图中的数据。一旦用户将鼠标悬停在该数据所属的国家/地区上,我就想渲染该数据。现在,我希望将坐标绘制为鼠标悬停处的注释,但是我需要数据

class EditableLabel extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            text: props.value,
            editing: false
        };
        this.initEditor();
        this.edit = this.edit.bind(this);
        this.save = this.save.bind(this);
    }

    initEditor() {
        this.editor = <input type="text" defaultValue={this.state.text} onKeyPress={(event) => {
            const key = event.which || event.keyCode;
            if (key === 13) { //enter key
                this.save(event.target.value)
            }
        }} autoFocus={true}/>;
    }

    edit() {
        this.setState({
            text: this.state.text,
            editing: true
        })
    };

    save(value) {
        this.setState({
            text: value,
            editing: false
        })
    };

    componentDidUpdate() {
        this.initEditor();
    }

    render() {
        return this.state.editing ?
            this.editor
            : <p onClick={this.edit}>{this.state.text}</p>
    }
}

//and use it like <EditableLabel value={"any external value"}/>;

和fowling代码以将数据悬停在鼠标悬停的位置

enter code genertate() : Map_Figure, Map_Graph = plt.subplots()
dataset = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
world = pd.DataFrame(dataset[['name', 'geometry', 'iso_a3']])
data2 = (records['Location'].value_counts()).reset_index()
data2.columns = ['name', 'Number']
data2['Number'] = data2['Number'].apply(int)
annot = Map_Graph.annotate("", xy=(0, 0), xytext=(20, 20), textcoords="offset points",
                    bbox=dict(boxstyle="round", fc="w"),
                    arrowprops=dict(arrowstyle="->"))
datum = world.set_index('name').join(data2.set_index('name'))

World = geopandas.GeoDataFrame(datum)
#print(Map_Graph)
basePlot = World.plot(ax=Map_Graph, column='Number', linewidth=0.1, edgecolor='black', cmap='nipy_spectral',
                      vmin=World['Number'].min(), vmax=World['Number'].max(), legend=True)
# worldPlot= World.plot(ax=Map_Graph, color= 'white', edgecolor='black', cmap='tab10', scheme='QUANTILES', figsize=(8, 4))

locations = data2.values
box = []
for word, count in locations[:10]:
    string = '%s | %s posts' % (word, human_format(count))
    if len(string) >= 27:
        string = string[:27] + " \n" + string[27:]
    else:
        string = string
    box.append(string)

s = '\n'.join(box)
mapText = '%s ' % (s)
Map_Graph.text(-340, -80, mapText, size='small', wrap=True,
               bbox={'boxstyle': 'round', 'facecolor': 'white', 'alpha': 0.5, 'pad': 0.8})

Map_Graph.set_axis_off()
Map_Figure.set_tight_layout(True)
Map_Figure.savefig("Report/data/Map.png")
mapCursor(Map_Graph)
Map_Figure.set_size_inches(6, 3.3)



return Map_Figure,basePlothere

0 个答案:

没有答案