【问题标题】:python matplotlib scatterpython matplotlib 散点图
【发布时间】:2011-05-26 21:51:52
【问题描述】:

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

感谢您的帮助。


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()

【问题讨论】:

    标签: python oracle matplotlib


    【解决方案1】:

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

    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

    【讨论】:

    • Oracle 中没有 DATEPART 但这让我找到了 TO_NUMBER(to_char(end_time, 'HH24')) ,它起作用了。谢谢!所以我最好的猜测是我得到了错误,因为 matplotlib 想要一个数字而不是像 to_char 产生的字符串。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 2021-09-04
    • 1970-01-01
    相关资源
    最近更新 更多