"""排名圆弧条形图 Restored/adapted from supplied screenshots [64, 65, 66]. Source: 小明的代码美学 (as shown in supplied screenshots). This is a runnable restoration, not a byte-for-byte original source file. See SOURCE.md for missing inputs and documented corrections. """ import numpy as np import pandas as pd import matplotlib.pyplot as plt from matplotlib.colors import LinearSegmentedColormap, Normalize, to_hex from matplotlib.cm import ScalarMappable from pathlib import Path # Missing .mplstyle files are replaced only by explicit, portable display defaults. plt.rcParams.update({'font.sans-serif':['Microsoft YaHei','DejaVu Sans'], 'axes.unicode_minus':False,'figure.facecolor':'white','axes.facecolor':'white', 'axes.spines.top':False,'axes.spines.right':False,'font.size':9}) from faker import Faker Faker.seed(6);np.random.seed(6) fake=Faker() company_name=[fake.company() for _ in range(16)] growth_data=np.sort(np.random.uniform(0,100,16)) def create_colors(hex_colors,data): cmap=LinearSegmentedColormap.from_list('custom',hex_colors) sm=ScalarMappable(norm=Normalize(min(data),max(data)),cmap=cmap) return [sm.to_rgba(v)[:3] for v in data] fig,ax=plt.subplots(figsize=(10,8),subplot_kw={'projection':'polar'},dpi=150) max_value=max(growth_data)*2.75 colors=create_colors(['#214e81','#a55d75'],growth_data) inner_radius=15 for i,(label,value) in enumerate(zip(company_name,growth_data)): inner_radius+=1.7;ring_width=1.5 theta_start=0;theta_end=value/max_value*2*np.pi ax.bar((theta_start+theta_end)/2,height=ring_width,width=theta_end-theta_start,bottom=inner_radius,color=colors[i],alpha=.85) attr=dict(color=colors[i],rotation=np.degrees(theta_end)+5,ha='left') if theta_end