python画bar图

import numpy as np
import matplotlib.pyplot as plt

plt.style.use('ggplot')
logistic_regression = [
    [184, 111, 76],
    [116, 80, 62],
    [15, 6, 3]
]
k_means = [
    [274, 157, 106],
    [197, 121, 87],
    [143, 61, 33]
]
engines = ['Hadoop', 'HadoopBinMem', 'Spark']
colors = 'rgb'

fig, (ax1, ax2) = plt.subplots(ncols=2)

idx = np.arange(len(logistic_regression[0]))
n = len(logistic_regression)
width = 1.0 / (n + 1)
for i in range(n):
    ax1.bar(idx + i * width, logistic_regression[i], width, color=colors[i], alpha=0.5)
    xpos = idx + (i + 0.5) * width
    ypos = logistic_regression[i]
    for j in range(len(ypos)):
        ax1.text(xpos[j], ypos[j], str(ypos[j]), ha='center', va='bottom', rotation=90)
ax1.legend(engines)
ax1.set_xticks(idx + 0.5, [25, 50, 100])
ax1.set_xlabel('Number of machines')
ax1.set_ylabel('Iteration time (s)')
ax1.set_title('Logistic Regression')

idx = np.arange(len(k_means[0]))
n = len(k_means)
width = 1.0 / (n + 1)
for i in range(n):
    ax2.bar(idx + i * width, k_means[i], width, color=colors[i], alpha=0.5)
    xpos = idx + (i + 0.5) * width
    ypos = k_means[i]
    for j in range(len(ypos)):
        ax2.text(xpos[j], ypos[j], str(ypos[j]), ha='center', va='bottom', rotation=90)
ax2.legend(engines)
ax2.set_xticks(idx + 0.5, [25, 50, 100])
ax2.set_xlabel('Number of machines')
ax2.set_ylabel('Iteration time (s)')
ax2.set_title('K-Means')

plt.tight_layout()
plt.show()

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值