Ma Y
Ma Y

Reputation: 706

Matplotlib makes empty plot using plt.plot but shows the plot using plt.scatter

I am going to plot the results of a for loop and if statement inside of it.

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. What should I do to have plot of Unu vs nu with lines not dots?

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()

Upvotes: 0

Views: 98

Answers (1)

Sheldore
Sheldore

Reputation: 39052

You code is not runnable but you can do something along the following lines:

  • Initialize two lists to store nu and Unu(xx)
  • Append them inside the for loop
  • Plot them outside the for loop

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() 

Upvotes: 1

Related Questions