Tôi đang cố tạo biểu đồ trực quan hấp dẫn bằng Python. Tôi đã sử dụng ví dụ của Randal Olson http://www.randalolson.com/2014/06/28/how-to-make-beautiful-data-visualizations-in-python-with-matplotlib/ ở đây và cố gắng thực hiện một số điều chỉnh.Thay đổi xlim theo ngày trong Matplotlib
Dữ liệu của tôi rất đơn giản,
dispute_percentage
Out[34]:
2015-08-11 0.017647
2015-08-12 0.004525
2015-08-13 0.006024
2015-08-14 0.000000
2015-08-15 0.000000
2015-08-17 0.000000
Vấn đề là các dữ liệu bắt đầu tải tại tháng hai năm 2015, và tôi muốn bắt đầu hiển thị ở Tháng Tư năm 2015.
Dưới đây là mã của tôi
from __future__ import division
from collections import OrderedDict
import pandas as pd
from collections import Counter
from pylab import *
import datetime as datetime
dispute_percentage.plot(kind = 'line')
plt.xlabel('Date')
plt.ylabel('Percent')
plt.title('Percent Disputes In FY2015')
# Remove the plot frame lines. They are unnecessary chartjunk.
ax = plt.subplot(111)
ax.spines["top"].set_visible(False)
ax.spines["bottom"].set_visible(False)
ax.spines["right"].set_visible(False)
ax.spines["left"].set_visible(False)
# Ensure that the axis ticks only show up on the bottom and left of the plot.
# Ticks on the right and top of the plot are generally unnecessary chartjunk.
ax.get_xaxis().tick_bottom()
#ax.get_yaxis().tick_left()
# Limit the range of the plot to only where the data is.
# Avoid unnecessary whitespace.
datenow = datetime.datetime.now
dstart = datetime(2015,4,1)
print datenow
plt.ylim(0, .14)
plt.xlim(dstart, datenow)
Các xlim là những gì tôi đang đấu tranh với. Tôi gặp lỗi
File "C:/Mypath/name.py", line 52, in <module>
dstart = datetime(2015,4,1)
TypeError: 'module' object is not callable
Nếu có ai có thể giúp điều này thật tuyệt vời. Ngoài ra bất kỳ đầu vào trên cố gắng để làm cho nó đẹp hơn cũng sẽ được đánh giá cao.
'datetime.datetime.now' không nhận được c alled, chỉ nhận được bí danh. Thêm parens. Ngoài ra, không gọi 'từ gói nhập *. Đó là yucky. :) ** Chỉnh sửa: ** và 'nhập datetime như datetime' là dư thừa. ** Chỉnh sửa thứ hai: ** 'dstart = ...' phải là 'dstart = datetime.datetime (2015, 4, 1)' –
@AndyKubiak Cảm ơn câu trả lời. Cách tốt hơn để làm 'từ việc nhập gói * là gì? – jenryb
'gói nhập ' –