簡體   English   中英

Matplotlib 使用 plt.plot 使 plot 為空,但使用 plt.plot 顯示 Z32FA6E1B78A9D4028953E6056CZ

[英]Matplotlib makes empty plot using plt.plot but shows the plot using plt.scatter

我要去 plot 的結果for loop和它里面的if statement

I want to have plot with lines but once I use plt.plot the plot will be empty but once I try scatter I have plot with dots. 我應該怎么做才能讓Unu vs nu的 plot 用線而不是點?

if inp==0:
        print('***')
        print('0 Is not acceptable ')
        print('***')
    else:
        for xx in range(1,819):
            ...# lines of code
            if inp<0:
                if lim > 1:
                    pass
                else:
                    nu = dfimppara.iloc[xx, 1] *115
                    plt.scatter(Unu(xx), nu)
            else:
                ...# lines of code
plt.show()

您的代碼不可運行,但您可以執行以下操作:

  • 初始化兩個列表來存儲nuUnu(xx)
  • Append 他們在for循環里面
  • Plot 它們在for循環之外

if inp==0:
    print('***')
    print('0 Is not acceptable ')
    print('***')
else:
    nu_list = []
    Unu_list = []
    for xx in range(1,819):
        ...# lines of code
        if inp<0:
            if lim > 1:
                pass
            else:
                nu_list.append(dfimppara.iloc[xx, 1] *115)
                Unu_list.append(Unu(xx))
            plt.plot(Unu_list, nu_list)
        else:
            ...
plt.show() 

暫無
暫無

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

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