我在構建我的第一個線圖時遇到了一些主要問題,目前我一直在努力工作和研究我的錯誤,很長一段時間都在耗盡所有努力。如何爲Python格式化日期時間線圖散景/ matplotlib日期時間和圖形問題
我有以下格式的銷售日期時間示例數據。該數據是從我的MySQL數據庫導入
2015-12-30 01:58:00 10
2015-12-30 01:59:00 16
2015-12-30 02:00:00 21
2015-12-30 02:01:00 5
2015-12-30 02:02:00 2
2015-12-30 02:03:00 4
2015-12-30 02:04:00 11
2015-12-30 02:06:00 5
2015-12-30 02:07:00 10
我上線圖努力工作,想完成在這兩個背景虛化和matplotlib線圖。我的第一個選擇是散景線圖示例here。
我正在使用的matplotlib腳本在下面註釋。
我收到了許多許多錯誤,並會在下面列出錯誤。錯誤的總體概要導致我相信我的日期時間格式不正確,我不明白在matplotlib中格式化的自動日期時間。 我也一直使用正則表達式對日期進行排序並以正確的格式打印日期。
#row[0] is the date
#row[1] is the sales
2015-12-30 02:09:00 1
2015-12-30 02:10:00 3
2015-12-30 02:12:00 2
2015-12-30 02:13:00 1
2015-12-30 02:14:00 18
2015-12-30 02:15:00 1
2015-12-30 02:16:00 10
2015-12-30 02:17:00 2
背景虛化的例子
import numpy as np
from bokeh.plotting import figure, output_file, show
import utils
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
# the import from MYSQL works great and data prints 100% works great
db = MySQLdb.connect("all my database stuff")
cur = db.cursor()
cur.execute("SELECT Statement")
#row[0] is the date in the format above "2015-12-30 02:09:00"
#row[1] is the sales in the format above "1"
try:
for row in cur.fetchall():
date = row[0]
sales = row[1]
#regex to strip date hypens and colons replace with spaces
#date_clean = re.sub('[^A-Za-z0-9]+', '', date)
print date,
print sales
#print date_clean prints with no extra characters
except:
print "error: unable to fetch data"
# prepare some data
x = 'date'
#x = 'date_clean'
y = 'sales'
# output to static HTML file
output_file("lines.html", title="line plot example")
# create a new plot with a title and axis labels
p = figure(title="example chart", x_axis_label='x', y_axis_label='y')
# add a line renderer with legend and line thickness
p.line(x, y, legend="Temp.", line_width=2)
# show the results
show(p)
當前錯誤,雖然我已經通過數百個錯誤的工作。 「lines.html」打開了一個框,但沒有行,日期或銷售。
No handlers could be found for logger "/usr/local/lib/python2.7/dist-packages/bokeh/validation/check.pyc"
(process:20113): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
這裏是我使用
x = date_clean
y = sales
plt.plot_date(x=date_clean, y=sales)
plt.title("example chart")
plt.ylabel("sales")
plt.grid(True)
plt.show()
"""
有人點我在正確的方向上matplotlib代碼。任何人都可以幫助使用正確格式的日期時間散景或matplotlib 要求執行一個正確的線圖,並有人可以解釋當前的錯誤。
我不知道「散景」,但是你用'matplotlib'得到的錯誤是什麼? –
for matplotlib我得到了QT輸出框圖1.圖中只有一個藍色圓點。除了標準的後退按鈕之外,框周圍是空的。使用reg表達式時出現對角線錯誤 – jedimonk
:error dt = datetime.datetime.fromordinal(ix).replace(tzinfo = UTC) OverflowError:有符號整數大於最大值 – jedimonk