gpt4 book ai didi

python matplotlib 散点图

转载 作者:太空宇宙 更新时间:2023-11-04 06:28:12 26 4
gpt4 key购买 nike

我正在使用 matplotlib 对 Oracle 表中的一些数据进行散点图绘制。其中一个字段是 DATE,在下面的查询中将其转换为 to_char 时出现错误。我想按 00-23 小时而不是日期来散点图。所以Y轴应该显示00-23。请参阅下面的代码示例以及错误。

感谢您的帮助。

Scatter Plot By Day


import cx_Oracle, os
import numpy
import matplotlib.pyplot as plt

这行得通

sql = """select number_of_small_reads, number_of_small_writes, number_of_large_reads, number_of_large_writes, end_time from schema.table order by end_time"""

这行不通

sql = """select number_of_small_reads, number_of_small_writes, number_of_large_reads, number_of_large_writes, to_char(end_time, 'HH24') e from schema.table order by e"""

我收到以下错误:“无法使用灵活类型执行 reduce”

conn = cx_Oracle.Connection("user/password@server:1521/database")
cursor = conn.cursor()
cursor.execute(sql)
rowset = cursor.fetchall()
cursor.close()
cx1 = []
cx2 = []
cx3 = []
cx4 = []
cy = []
cx1, cx2, cx3, cx4, cy = zip(*rowset)

ax = plt.figure().add_subplot(111)
ax.scatter(cx1, cy, s=9, c='b', marker='o', label='number_of_small_reads')
ax.scatter(cx2, cy, s=9, c='r', marker='o', label='number_of_small_writes')
ax.scatter(cx3, cy, s=9, c='g', marker='o', label='number_of_large_reads')
ax.scatter(cx4, cy, s=9, c='y', marker='o', label='number_of_large_writes')
plt.legend(shadow=True)
plt.title('Python Generated Chart')
plt.xlabel('IOPS')
plt.ylabel('By Date')
plt.xlim(0)
plt.show()
conn.close()

最佳答案

您可以只选择小时而不是日期。

SELECT .. DATEPART(mm, end_date) AS end_hour

http://www.bennadel.com/blog/172-Ask-Ben-Selecting-Parts-of-a-Date-Time-Stamp-In-SQL.htm

关于python matplotlib 散点图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6145552/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com