2012-09-11 13 views
5

मैं फ्लोट की ग्राफ सूची में Matplotlib का उपयोग कर रहा हूं। यदि मेरी सूची 100 फ्लोट लंबी है तो ग्राफ उचित रंग प्रदर्शित करता है। लेकिन अगर सूची 785 लंबी है तो यह केवल काला रंग दिखाती है। कोड यहाँ है।Matplotlib - बार ग्राफ लाइन रंग काला क्यों है?

import numpy as np 
import matplotlib.pyplot as plt 
import Image 

Consensus = [] 
Prediction = [] 
Final = [] 
for line in open('1.out').readlines(): 
    words = line.split() 
    Consensus.append(float(words[10])) 
    Prediction.append(int(words[11])) 

for i,j in zip(Consensus,Prediction): 
    Final.append(i*j) 

max_score = 3 
length = 785 
ind = np.arange(length) # the x locations for the groups 
width = 1  # the width of the bars: can also be len(x) sequence 

p1 = plt.bar(ind, Consensus, width, color='red') 
p2 = plt.bar(ind, Final, width, color='blue') 

plt.ylabel('Scores') 
plt.title('Scores by group and gender') 
plt.xticks(np.arange(0,length,50)) 
plt.yticks(np.arange(0,max_score,0.2)) 
plt.savefig('testplot.png') 
Image.open('testplot.png').save('testplot.jpg','JPEG') 

यह सूची 785 लंबाई में प्रोग्राम की तस्वीर है। This is the picture of the program when the list is 785 in length.

यह तब होता है जब सूची 99 इंच लंबी होती है। This is when the the list is 99 in length.

फ़ाइल यहाँ उपलब्ध है - http://pastebin.com/HhPhgPDG

तुम बस अन्य मामले की जांच के लिए इस फाइल के पहले 100 लाइनों कॉपी बदल सकते हैं। आपको लंबाई चर को फ़ाइल में लाइनों की संख्या में बदलना चाहिए।

धन्यवाद।

उत्तर

24

आपके बार की सीमाएं काला हैं। यह संभव है कि जब आपके पास इतने सारे सलाखों हों, तो वे बहुत संकीर्ण हो जाते हैं और सीमाएं एक साथ मिलती हैं, इसलिए आप केवल सीमाओं को देखते हैं, न कि रंगीन अंदरूनी। यह देखने के लिए कि रंग वहां हैं या नहीं, अपने ग्राफ पर ज़ूम इन करने का प्रयास करें। सीमाओं को हटाने के लिए आप edgecolor='none' तर्क bar पर भी पास कर सकते हैं।

1

आपके बार इतने घने हो रहे हैं कि केवल सीमाएं दिखाई दे रही हैं। जैसे ही वे काले होते हैं, आप मुख्य रूप से काले दिखते हैं। इस को हल करने के दो संभव तरीके:

क) अपने सलाखों

ख की चौड़ाई बढ़ाने के) अपने सलाखों

की सीमाओं को दूर
संबंधित मुद्दे