I am trying to replicate this:
我已经走得很远了:
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import numpy as np
import pandas as pd
colors = ["#CC5A43","#CC5A43","#2C324F"]
data = {
"year": [2004, 2022, 2004, 2022, 2004, 2022],
"countries" : [ "Denmark", "Denmark", "Norway", "Norway","Sweden", "Sweden",],
"sites": [4,10,5,8,13,15]
}
df= pd.DataFrame(data)
df = df.sort_values(['countries' ,'year' ], ascending=True ).reset_index(drop=True)
df['ctry_code'] = df.countries.astype(str).str[:2].astype(str).str.upper()
df['year_lbl'] ="'"+df['year'].astype(str).str[-2:].astype(str)
df['sub_total'] = df.groupby('year')['sites'].transform('sum')
no_bars = df.sub_total.max()
sub_totals = df.sub_total.unique()
years= df.year.unique()
fig, axes = plt.subplots(nrows=2, ncols=1,figsize=(6, 6), subplot_kw=dict(polar=True))
fig.tight_layout(pad=3.0)
colors = [["#CC5A43"]*4 +["#2C324F"]*5 + ["#5375D4"]*13,
["#CC5A43"]*10 +["#2C324F"]*8 + ["#5375D4"]*15]
for sub_total, year,color,ax in zip( sub_totals, years,colors,axes.ravel()):
angles = np.arange(0,2*np.pi,2*np.pi/sub_total)
ax.plot([angles, angles],[0,1],lw=4, c="#CC5A43")
ax.set_rorigin(-4)
ax.set_theta_zero_location("N")
ax.set_yticklabels([])
ax.set_xticklabels([])
ax.grid(False)
ax.spines[['polar','inner']].set_color('w')
ax.text(np.pi/2,-3.2, year,va="center" )
for i, j in enumerate(ax.lines):
j.set_color(color[i])
#add legend
color_legend = [ "#A54836", "#5375D4", "#2B314D",]
lines = [Line2D([0], [0], color=c, linestyle='-', lw=4,) for c in color_legend]
labels = df.countries.unique().tolist()
plt.legend(lines, labels,
bbox_to_anchor=(1.5, -0.02), loc="lower center",
frameon=False, fontsize= 10)
但我真的在挠头,不知道如何做注解的"箭头":
我希望‘-(’能行得通,但它不行.
我的问题是,我需要为这个创建我自己的arrwostyle(这是一个好的参考资料吗?),或者有没有更明显的方法来做,而我完全错过了它?