学习、修改、参考自: https://mp.weixin.qq.com/s/lP_zc3moRpoccBYAWIFR1Q
import pandas as pd
import numpy as np
from palettable.colorbrewer.colorbrewer import get_map
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
values = np.arange(10,0,-1)*100
labels = ["北京","广东", "浙江", "江苏", "四川", "湖北", "上海", "深圳", "重庆", "天津"]
width = 2*np.pi/len(labels)
theta = np.linspace(0, 2*np.pi, len(labels), endpoint=False) + width/2
colors = get_map("Spectral", "diverging", len(labels), reverse=True).hex_colors
fig = plt.figure(figsize=(8, 8), dpi=100)
ax = fig.add_subplot(111, projection="polar")
ax.bar(theta, values, width=width, color=colors, alpha=0.8)
for i,j in zip(range(len(labels)),colors):
ax.text(theta[i], values[i] + 120,
"{}\n{}亿".format(labels[i], values[i]),fontsize=14-i*2/3,
color=j, va="center", ha="center")
ax.set_theta_direction(1)
ax.set_theta_offset(np.pi/1)
ax.set_axis_off()
ax.set_title("折扇图", fontsize=20);
import pandas as pd
import numpy as np
from palettable.colorbrewer.colorbrewer import get_map
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
labels1 = ['重庆', '北京', '天津', '上海']
values1 = [200, 160, 150, 100]
labels2 = [
['渝北区', '江北区', '巴南区'],
['朝阳区', '西城区', '丰台区'],
['和平区', '河东区', '河西区'],
['黄浦区', '长宁区', '虹口区']]
values2 = [
[100, 60, 40],
[100, 40, 20],
[100, 40, 10],
[60, 20, 20]]
colors1 = ['#177cb0', '#9d2933', '#0aa344', '#E6550D']
colors2 = [
['#2894FF', '#84C1FF', '#C4E1FF'],
['#db5a6b', '#f47983', '#ffb3a7'],
['#73C08B','#A8E0B7', '#CBEAD1'],
['#ff7500', '#FDAE6B', '#FFE4B5']]
fig, ax = plt.subplots(figsize=(9,9))
ax.pie(x=values1,
labels=labels1,
explode=[0.01]*len(labels1),
colors=colors1,
startangle=180,
labeldistance=1.06,
textprops={'fontsize': 20},
wedgeprops={'alpha': 0.8, 'width': 0.2}
)
ax.pie(x=flatten(values2),
labels=flatten(labels2),
explode=[0.01]*len(flatten(labels2)),
colors=flatten(colors2),
labeldistance=0.75,
startangle=180,
radius=0.79,
textprops={'va': 'center', 'ha': 'center','fontsize': 14},
rotatelabels=True,
wedgeprops={'alpha': 0.8, 'width': 0.4}
)
fig.set_facecolor('white');
import pandas as pd
import numpy as np
from scipy import stats
from matplotlib import ticker
from palettable.colorbrewer.colorbrewer import get_map
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
def plot_ridges(ax, X, Y1, buttoms, labels, colors, **kw):
if np.array(X).ndim == 1:
X = [X]*len(Y1)
n = 0
for y in Y1:
y = np.array(y) - np.min(np.array(y))
ax.fill_between(X[n], y + buttoms[n], buttoms[n], where=y>0, color=colors[n],
label=labels[n], **kw)
ax.plot(X[n], y + buttoms[n], color=colors[n])
n += 1
return ax
X = np.arange(-8, 8, 0.1)
Y = [np.apply_along_axis(lambda x: stats.norm(0,1).pdf(x), 0, X)*2,
np.apply_along_axis(lambda x: stats.norm(-2,1).pdf(x), 0, X)*2,
np.apply_along_axis(lambda x: stats.norm(-4,1).pdf(x), 0, X)*2,
np.apply_along_axis(lambda x: stats.norm(2,1).pdf(x), 0, X)*2,
np.apply_along_axis(lambda x: stats.norm(4,1).pdf(x), 0, X)*2]
colors = get_map("Set2", "qualitative", len(Y), reverse=False).hex_colors
buttoms = [0, 1, 2, 3, 4]
labels = ["y1", "y2", "y3", "y4", "y5"]
fig, ax = plt.subplots(figsize=(10, 10))
plot_ridges(ax, X, Y, buttoms, labels, colors)
ax.legend(loc='best', title="图例")
ax.yaxis.set_major_locator(ticker.NullLocator())
ax.set_title("山峦图", fontdict={'fontsize': 15},backgroundcolor='#ffc773',fontweight='bold',color='white')
更多请查看参看文章
|