简体   繁体   English

python中的有效地图绘制

[英]Efficient map plotting in python

Using plotly, I've learned to plot maps that represent stuff like 'salary per country' or 'number of XX per country' etc . 使用plotly,我学会了绘制表示诸如“每个国家的薪水”或“每个国家的XX数量”之类的东西的地图。

Now I'd like to plot the following : say I'm interested in three quantities A,B and C, I would like to plot, for each country, little circles with a size that gets bigger when the value gets bigger, for example : 现在,我想绘制以下内容:例如,我对A,B和C的三个数量感兴趣,我想绘制每个国家的小圆圈,例如,当值越大时,其大小越大。 :

USA : A=10, B=12,C=3 , I would have 3 circles in the US zone, circle(B)>circle(A)>circle(C). 美国:A = 10,B = 12,C = 3,我在美国区域将有3个圆圈,即circle(B)> circle(A)> circle(C)。

My dataframe has 4 columns : columns=['Country','quantity_A','quantity_B','quantity_C'] 我的数据框有4列: columns=['Country','quantity_A','quantity_B','quantity_C']

How can I plot a map that looks like what I described. 如何绘制看起来像我所描述的地图。 I'm willing to use any library that allows that (the simpler the better of course). 我愿意使用任何允许的库(当然,越简单越好)。

Thanks ! 谢谢 !

Using matplotlib you can draw a scatter plot as follows, where the size of the scatter point is given by the quantity in the respective column. 使用matplotlib可以如下绘制散点图,其中散点的大小由相应列中的数量给出。

import matplotlib.pyplot as plt
import numpy as np; np.random.seed(1)
import pandas as pd

countries = ["USA", "Israel", "Tibet"]
columns=['quantity_A','quantity_B','quantity_C']

df = pd.DataFrame(np.random.rand(len(countries),len(columns))+.2,
                  columns=columns, index=countries)

fig, ax=plt.subplots()

for i,c in enumerate(df.columns):
    ax.scatter(df.index, np.ones(len(df))*i, s = df[c]*200, c=range(len(df)), cmap="tab10")

ax.set_yticks(range(len(df.columns)))
ax.set_yticklabels(df.columns) 
ax.margins(0.5) 
plt.show()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM