气泡图
| |
| |
| |
| |
| |
| import matplotlib.pyplot as plt |
| import numpy as np |
| |
| income = np.array([5550, 7500, 10500, 15000, 20000, 25000, 30000, 40000]) |
| outcome = np.array([800, 1800, 1250, 2000, 1800, 2100, 2500, 3500]) |
| nums = np.array([5, 3, 10, 5, 12, 20, 8, 10]) |
| |
| |
| |
| |
| plt.scatter(income, outcome, s=nums*30, c=nums, cmap='Reds') |
| |
| |
| plt.colorbar() |
| plt.show() |
面积图
| |
| |
| |
| |
| |
| import matplotlib.pyplot as plt |
| import numpy as np |
| |
| |
| plt.rcParams['font.sans-serif'] = ['SimHei'] |
| plt.rcParams['axes.unicode_minus'] = False |
| |
| |
| plt.figure(figsize=(8,6), dpi=120) |
| days=np.arange(7) |
| sleeping = [7,8,6,11,7,8,13] |
| eating = [2,3,4,3,2,1,1] |
| working = [7,8,7,2,2,7,10] |
| playing = [8,5,7,8,13,11,12] |
| |
| |
| |
| |
| plt.stackplot(days, sleeping, eating, working, playing) |
| |
| |
| |
| plt.xticks(days, labels=[f'星期{x}' for x in '一二三四五六日']) |
| |
| |
| plt.legend(['睡觉','吃饭','工作','娱乐'], loc='upper right', fontsize=10) |
| plt.show() |
雷达图
| |
| |
| |
| |
| |
| |
| |
| import matplotlib.pyplot as plt |
| import numpy as np |
| |
| |
| plt.rcParams['font.sans-serif'] = ['SimHei'] |
| plt.rcParams['axes.unicode_minus'] = False |
| |
| |
| labels = np.array(['速度', '力量', '经验', '防守', '发球', '技术']) |
| |
| malong_values = np.array([93, 95, 98, 92, 96, 97]) |
| shuigu_values = np.array([30, 40, 65, 80, 45, 60]) |
| |
| |
| angles = np.linspace(0, 2*np.pi, labels.size, endpoint=False) |
| |
| |
| |
| malong_values = np.append(malong_values, malong_values[0]) |
| shuigu_values = np.append(shuigu_values, shuigu_values[0]) |
| angles = np.append(angles, angles[0]) |
| |
| |
| fig = plt.figure(figsize=(8, 8), dpi=120) |
| |
| ax = plt.subplot(projection='polar') |
| |
| |
| plt.plot(angles, malong_values, color='r', linewidth=2, label='马龙') |
| plt.fill(angles, malong_values, facecolor='r', alpha=0.3) |
| plt.plot(angles, shuigu_values, color='b', linewidth=2, label='水谷隼') |
| plt.fill(angles, shuigu_values, facecolor='b', alpha=0.2) |
| |
| |
| ax.legend() |
| plt.show() |
玫瑰图
| |
| |
| |
| |
| |
| |
| import matplotlib.pyplot as plt |
| import numpy as np |
| |
| |
| plt.rcParams['font.sans-serif'] = ['SimHei'] |
| plt.rcParams['axes.unicode_minus'] = False |
| |
| group1 = np.random.randint(20, 50, 4) |
| group2 = np.random.randint(10, 60, 4) |
| x = np.array([f'A组-Q{i}' for i in range(1, 5)] + [f'B组-Q{i}' for i in range(1, 5)]) |
| y = np.array(group1.tolist() + group2.tolist()) |
| |
| |
| theta = np.linspace(0, 2 * np.pi, x.size, endpoint=False) |
| width = 2 * np.pi / x.size |
| |
| |
| colors = np.random.rand(8, 3) |
| |
| |
| ax = plt.subplot(projection='polar') |
| |
| |
| plt.bar(theta, y, width=width, bottom=0.0, color=colors, alpha=0.5) |
| |
| |
| ax.set_thetagrids(theta * 180 / np.pi, x, fontsize=10) |
| |
| plt.show() |
3D图表
| |
| |
| |
| import matplotlib.pyplot as plt |
| import numpy as np |
| from mpl_toolkits.mplot3d import Axes3D |
| |
| |
| fig = plt.figure(figsize=(8,6), dpi=120) |
| |
| |
| ax = Axes3D(fig, auto_add_to_figure=False) |
| fig.add_axes(ax) |
| |
| x = np.arange(-2, 2, 0.1) |
| y = np.arange(-2, 2, 0.1) |
| x, y = np.meshgrid(x, y) |
| z = (1 - y ** 5 + x ** 5) * np.exp(-x ** 2 - y ** 2) |
| |
| |
| ax.plot_surface(x, y, z) |
| plt.show() |
| |
| |
| |
| |
| |
| |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步