Ich versuche, eine visuell ansprechende Grafik in Python zu machen. Ich habe Randal Olsons Beispiel http://www.randalolson.com/2014/06/28/how-to-make-beautiful-data-visualizations-in-python-with-matplotlib/ hier benutzt und versucht, einige Anpassungen vorzunehmen.Ändern der xlim nach Datum in Matplotlib
simple Meine Daten sind,
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
Das Problem ist, dass die Daten im Februar 2015 das Laden beginnt, und ich möchte im April Anzeige starten 2015
Hier mein Code
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)
Der Xlim ist was ich kämpfe. Ich erhalte den Fehler
File "C:/Mypath/name.py", line 52, in <module>
dstart = datetime(2015,4,1)
TypeError: 'module' object is not callable
Wenn jemand mit diesem helfen könnte, das groß wäre. Auch jede Eingabe über den Versuch, es hübscher zu machen, würde ebenfalls geschätzt werden.
'datetime.datetime.now' wird nicht c alled, nur Aliasing bekommen. Fügen Sie Parens hinzu. Rufe auch 'from package import *' nicht auf. Das ist eklig. :) ** Edit: ** und 'datetime als datetime importieren 'ist redundant. ** Second Edit: ** 'dstart = ...' sollte sein 'dstart = datetime.datetime (2015, 4, 1)' –
@AndyKubiak Danke für die Antwort. Was ist ein besserer Weg, um 'vom Paketimport *' zu machen? – jenryb
'Importpaket' –