python - 使用 matlib.plot 绘制二维图形
问题描述
我需要在 python 中使用 matlib.plot 绘制图形,如下所示:
实际上我正在使用绘制所有条形图的代码
bars = ('Optimum CPLEX', 'eUCB', 'ONETS', 'e-greedy')
y_pos = [1, 3, 5, 7]
y_pos_2 = [2, 4, 6, 8]
plt.ylabel('Average Reward \u03B7_i')
plt.suptitle('Optimal Model versus Heuristics')
name = 'grafics/11_reward_utilization.png'
# Create bars
plt.bar(y_pos, reward, color=['blue', 'blue', 'blue', 'blue'])
plt.bar(y_pos_2, utilization, color=['yellow', 'yellow', 'yellow', 'yellow'])
# Create names on the x-axis
plt.xticks(y_pos, bars)
# Show graphic
plt.savefig(name, transparent = True)
plt.show()
但结果我收到了一个包含所有条形但尺寸相同的图形,如下所示:
有人知道我如何在 y 轴上绘制这两个不同维度数据的图形时间?
谢谢你。
解决方案
你定义了reward
和utilization
???
您使用这些定义的示例对我有用:
import matplotlib.pyplot as plt
bars = ('Optimum CPLEX', 'eUCB', 'ONETS', 'e-greedy')
y_pos = [1, 3, 5, 7]
reward = [1,2,3,4]
y_pos_2 = [2, 4, 6, 8]
utilization = [4,3,2,1]
plt.ylabel('Average Reward \u03B7_i')
plt.suptitle('Optimal Model versus Heuristics')
name = '11_reward_utilization.png'
# Create bars
plt.bar(y_pos, reward, color=['blue', 'blue', 'blue', 'blue'])
plt.bar(y_pos_2, utilization, color=['yellow', 'yellow', 'yellow', 'yellow'])
# Create names on the x-axis
plt.xticks(y_pos, bars)
# Show graphic
plt.savefig(name, transparent=True)
plt.show()
推荐阅读
- php - 如何使用手动方法重试 Laravel 事务?
- sql-server - 消息 8152,级别 16,状态 14,字符串或二进制数据将被截断
- c# - 用于 Azure Blob 管理的 Azure.Storage.Blobs 与 Microsoft.WindowsAzure.Storage.Blob dll
- javascript - 在exceljs中插入一列
- firebase - 为什么 Firebase 这么晚才发送验证邮件?Firebase + 颤振
- arrays - 如何基于元素包含 textfield.text 的另一个字符串数组创建一个字符串数组。不知道如何以正确的方式过滤它:(
- go - 在confluent kafka go中阅读来自kafka主题的消息时如何使用确认?
- material-ui - 如何为包含 xs={12} 布局全宽的材质 ui 网格项编写 xs、sm、md、lg?
- regex - 正则表达式匹配单词和特殊字符之间的字符串
- list - 创建二维列表,然后在 Scala 中创建一个 DataFrame