Using plotly, I've learned to plot maps that represent stuff like 'salary per country' or 'number of XX per country' etc .
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 :
USA : A=10, B=12,C=3 , I would have 3 circles in the US zone, circle(B)>circle(A)>circle(C).
My dataframe has 4 columns : 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.
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.