2011-04-05 7 views
11

में y अक्ष का न्यूनतम मान लागू नहीं किया जा रहा है मैं matplotlib में एक vlines साजिश कर रहा हूं और मेरे पास सभी वाई मान डेटासेट में >=0 है। मैं चाहता हूं कि मेरी वाई धुरी नीचे 0 पढ़ने के लिए सबसे अधिक टिक टिके, लेकिन इसके बजाय, मुझे -500 मिलते हैं। है साजिश मैंmatplotlib vlines plot

#!/usr/bin/env python 

import numpy as np 
from matplotlib import pyplot as plt, dates as mdates 
import datetime as dt, time 

# Read the data and turn it into a numpy array 
#store = map(lambda line: map(int, line.strip().split()), open(name + '.txt').readlines()) 
store = [ 
    [1293606162197, 0, 0], 
    [1293605477994, 63, 0], 
    [1293605478057, 0, 0], 
    [1293605478072, 2735, 1249], 
    [1293606162213, 0, 0], 
    [1293606162229, 0, 0], 
] 

nstore = np.array(store) 

# Get arrays of each columns in the store array 
d = nstore[:,0] 
y1 = nstore[:,1] 
y2 = nstore[:,2] 

# Get arrays of values to be passed to matplotlib 
s = d/1000 
dts = map(dt.datetime.fromtimestamp, s) 
fds = mdates.date2num(dts) 

# new figure and subplot 
fig = plt.figure() 
ax = fig.add_subplot(111) 

# Plot using vlines 
ax.vlines(fds, [0], y1, 'red') 

# set xaxis tick settings 
ax.xaxis.set_major_locator(mdates.MinuteLocator()) 
ax.xaxis.set_major_formatter(mdates.DateFormatter('%m/%d %H:%M')) 

for label in ax.xaxis.get_ticklabels(): 
    label.set_rotation('vertical') 

fig.subplots_adjust(bottom=.25) 

# Set the y axis bottom limit to 0 
ax.set_ylim(bottom=0) # <<- THIS DOES NOT SEEM TO BE WORKING 

# Save the plot figure 
fig.savefig('out.png') 

और यहाँ: enter image description here

मेरे लिए किसी को भी इंगित कर सकते हैं मैं गलत क्या कर रहा हूँ

यहाँ कोड है? साथ ही, यदि आप उन दस्तावेज़ों को इंगित कर सकते हैं जिनके पास मुझे आवश्यक विवरण हैं, तो यह बहुत अच्छा होगा। धन्यवाद।

प्रश्न Creating graph with date and time in axis labels with matplotlib

उत्तर

19

की अनुवर्ती कार्रवाई है आप सीमा को मैन्युअल रूप से की तरह डेटा की साजिश रचने के बाद सेट कर सकते हैं,:

pyplot.ylim(ymin=0) 

क्या होता है matplotlib समायोजित कर देता है कि साजिश तो सीमित करता है यह "सर्वश्रेष्ठ" दिखता है। कभी-कभी, इसका मतलब है कि आपके डेटा की सख्त सीमा से आगे बढ़ना। साजिश के बाद आपको सीमाएं अपडेट करनी होंगी, क्योंकि प्रत्येक प्लॉट सीमा को अपडेट करता है (यदि मैं सही ढंग से समझता हूं)।

अब, अपने दृष्टिकोण काम कर सकते हैं, लेकिन आप सीमा निर्धारित करने के बाद आंकड़ा अपडेट करना होगा: (। यह matplotlib के नवीनतम संस्करण के साथ मैक ओएस एक्स पर IPython खोल में काम करता है)

ax.set_ylim(bottom=0) 
pylot.draw() 

+0

आह, धन्यवाद ईओएल, यह काम कर रहा है। क्या ऑब्जेक्ट उन्मुख शैली में इस विधि का समतुल्य है, क्योंकि मैं समानांतर में कई भूखंड करूँगा। –

+0

@Shrikant: मैंने अपने उत्तर में एक ऑब्जेक्ट उन्मुख दृष्टिकोण जोड़ा। – EOL

+0

मुझे 'TypeError मिलता है: draw_wrapper() को 'ax.draw()' के साथ कम से कम 2 तर्क (1 दिया गया)' मिलता है, जो उबंटू पर चल रहा है। –