-1

I'm trying to plot a curve through a very simple function :

def plotter(Taus, G2_data, titre) : 
    plt.figure()
    plt.title('{}'.format(titre))
    plt.xlabel('Tau (s)')
    plt.ylabel('g2 - 1')  
    plt.ylim(-1, 1.1)
    plt.xlim(-0.1, 7000)
    plt.plot()
    plt.show()
        
    return None

plotter(taus, Y, 'test')

taus and Y are two list of same length, with Y containing a few NaN values at the end. This code returns this : enter image description here

I have browsed a few posts : Matplotlib does not plot curve, Lines not showing up on Matplotlib graph and Matplotlib plt.show() isn't showing graph but none of them help me.

Does someone has an idea about why the curve isn't showing ? Thanks for the time.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Archerlite
  • 25
  • 4

1 Answers1

1

First of all, make sure the data is in the range of axis values you are plotting. And you have to pass the data you want to plot in plt.plot() like

plt.plot(Taus, G2_data)

If you need to remove NaN values and you are working with numpy:

mask = ~np.isnan(G2_data)
Taus, G2_data = Taus[mask], G2_data[mask]

Anyway, you can plot them.

thesydne
  • 57
  • 6
  • Thank you very much. Such a basic mistake... However, your code to remove Nans does not work because `TypeError: only integer scalar arrays can be converted to a scalar index`. I will figure it out. Thanks ! – Archerlite Jul 21 '23 at 11:21