簡體   English   中英

Matplotlib plt.plot與枚舉不起作用

[英]Matplotlib plt.plot with enumerate not working

import numpy as np 
import matplotlib.pyplot as plt 

array = np.array([[1,2,3,4,5,6],[10,20,30,40,50,60],[3,4,5,6,7,8],[100,200,300,400,500,600]])

def plot(list):
    fig = plt.figure()
    ax = fig.add_subplot(111)

    for a,i in enumerate(list.T):
        ax.scatter(i[0],i[1],c='red') # This is plotted
        ax.plot(i[2],i[3],'g--') # THIS IS NOT BEING PLOTTED !!!! 
    fig.show()

plot(array)

現在,我需要使用不同的array列表多次調用plot 因此,我的for循環無法刪除。 除了調用plt.plot之外,還有其他方法可以繪制虛線嗎?

這是我得到的情節:

在此處輸入圖片說明

如您所見,我沒有得到plt.plot(i[2],i[3],'g--') 為什么會這樣呢?

但是,當您使用相同的for循環打印值時:

In [21]: for a,i in enumerate(array.T):
    ...:     print i[2],i[3]
    ...:     
3 100
4 200
5 300
6 400
7 500
8 600

值已完美打印。 但是,未繪制它們。

刪除for循環:

ax.scatter(array[0],array[1],c='red')
ax.plot(array[0],array[1],'g--')

與您的代碼的問題是,你遍歷行,這是罰款單繪制點( ax.scatter ),但不能用於連接單獨點( ax.plot'--'選項):在每行只繪制該點與其自身之間的直線,顯然不會顯示在圖中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM