roberthsu2003 / __2024_05_05_sunday__

AI 人工智慧開發入門_python
29 stars 2 forks source link

請幫我畫以下的圖 #18

Open roberthsu2003 opened 1 month ago

roberthsu2003 commented 1 month ago

pie文件說明

labels = ['Nokia', 'Samsung', 'Apple', 'Lumia']
values = [20, 30, 45, 10]
colors =['yellow', 'green', 'red', 'blue']
截圖 2024-06-16 下午4 43 59
jonathan-sean commented 1 month ago

Python code:

# How to draw pie chart ?
# Please visit https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.pie.html
import matplotlib.pyplot as plt

def main():
    labels:list = ['Nokia', 'Samsung', 'Apple', 'Lumia']
    values:list = [20, 30, 45, 10]
    colors:list = ['yellow', 'green', 'red', 'blue']

    # 把 Nokia 切出來
    explode = (0.3, 0, 0, 0)

    fig = plt.figure(figsize=(4.9, 4.15))
    axes = fig.add_subplot()
    axes.pie(
        values,
        center=(0.25, 0.1),
        radius=1.3,
        labels=labels,
        colors=colors,
        shadow=True,
        startangle=180.0,
        explode=explode,
        autopct='%1.1f%%')
    plt.show()

if __name__ == "__main__":
    main()

Result: Figure_1

charlywang11 commented 1 month ago

請幫我畫以下的圖

labels = ['Nokia', 'Samsung', 'Apple', 'Lumia'] values = [20, 30, 45, 10] colors = ['yellow', 'green', 'red', 'blue']

import matplotlib.pyplot as plt

def main(): 
    labels = ['Nokia', 'Samsung', 'Apple', 'Lumia']
    values = [20, 30, 45, 10]
    colors = ['yellow', 'green', 'red', 'blue']

    figure = plt.figure(figsize=(5.0,5.0))
    axes = figure.add_subplot()
    axes.pie(values,explode=[0.3,0,0,0], labels=labels, colors=colors, autopct='%1.1f%%', shadow=1, startangle=180)
    plt.show()

if __name__ == '__main__':
    main()

image

mimionana2 commented 1 month ago
import matplotlib.pyplot as plt

labels = ['Nokia', 'Samsung', 'Apple', 'Lumia']
values = [20, 30, 45, 10]
explode = (0.2, 0, 0, 0)

fig, ax = plt.subplots()

ax.pie(values, labels=labels,explode=explode,autopct='%1.1f%%',
       shadow=True,startangle=180,
       colors=['yellow', 'green', 'red', 'blue'])

plt.show()
3
OrbAkatsuki commented 1 month ago

圓餅圖作業

import matplotlib.pyplot as plt

labels = ['Nokia', 'Samsung', 'Apple', 'Lumia']
values = [20, 30, 45, 10]
colors = ['yellow', 'green', 'red', 'blue']
explode = (0.3, 0, 0, 0)  

plt.pie(values, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', startangle=180, shadow=True)
plt.axis('equal')  
plt.show()

image