当前位置:首页 / 文章测试 / Matplotlib

Matplotlib

开始打字练习

import matplotlib.pyplot as plt

fruits = ['apple', 'banana', 'cherry', 'date']

bar_values = [10, 24, 18, 30]

line_values = [15, 20, 25, 28]

pie_values = bar_values

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 6))

ax1.bar(fruits, bar_values,

color='lightgreen',

width=0.6,

label='Sales (Bar)',

zorder=2,

edgecolor='black')

ax1.plot(fruits, line_values,

color='darkred',

marker='o',

linestyle='--',

linewidth=2,

label='Trend (Line)')

ax1.grid(True, linestyle='--', alpha=0.6, axis='y', zorder=1)

ax1.set_title('Fruit Sales Overview', fontsize=14)

ax1.set_xlabel('Fruit Type', fontsize=12)

ax1.set_ylabel('Value', fontsize=12)

ax1.legend(loc='upper left', fontsize=10)

for tick in ax1.get_xticklabels():

tick.set_fontsize(11)

for tick in ax1.get_yticklabels():

tick.set_fontsize(11)

explode = [0, 0.1, 0, 0]

colors = ['#ff9999','#66b3ff','#99ff99','#ffcc99']

ax2.pie(pie_values,

labels=fruits,

autopct='%1.1f%%',

startangle=140,

colors=colors,

explode=explode,

shadow=True,

textprops={'fontsize': 12})

ax2.set_title('Sales Distribution by Fruit', fontsize=14)

ax2.axis('equal')

plt.tight_layout()

plt.show()

声明:以上文章均为用户自行发布,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。