Python draws colorful pie charts

import matplotlib.pyplot as plt
import numpy as np

plt.style.use('seaborn-darkgrid')


# make data
x = [1, 2, 3, 4, 5]
colors = plt.get_cmap('Accent')(np.linspace(0.2, 0.7, len(x)))

# plot
fig, ax = plt.subplots()
ax.pie(x, colors=colors, radius=3, center=(4, 4),
       wedgeprops={
    
    "linewidth": 1, "edgecolor": "white"}, frame=True)

ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
       ylim=(0, 8), yticks=np.arange(1, 8))

plt.show()

insert image description here

colors = plt.get_cmap('Accent_r')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('BrBG')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('BuGn')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('BuPu')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('BuPu_r')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('CMRmap')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('Dark2')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('cubehelix')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('cubehelix_r')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('flag')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('gist_earth')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('gist_heat')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('Wistia')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('terrain')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('twilight')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('twilight_r')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('twilight_shifted')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('twilight_shifted_r')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('viridis')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('viridis_r')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('binary')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('bone')(np.linspace(0.2, 0.7, len(x)))

insert image description here

colors = plt.get_cmap('brg')(np.linspace(0.2, 0.7, len(x)))

insert image description here
References: https://matplotlib.org/stable/plot_types/stats/pie.html
Development tools: Pycharm

Guess you like

Origin blog.csdn.net/m0_38127487/article/details/132182665