jeudi 30 juillet 2020

if else statement python using plot parameters in function

I have an if else statement in my function that is not wokring the way i want it to. Mind you I am still learning python and all things programming.

I have a function to define a plot. Idea is to create a large python repo for data analysis.

def plots_timeseries(time=[],cond=[], depth=[], temp=[]):
    #-----------
    # CONDUCTIVITY PLOT
    #-----------
    if cond == []:
        print('there is no cond value')
        pass
    else:
        fig, ax1 = plt.subplots(1)
        plt.scatter(time,depth,s=15,c=cond)
        plt.show()

The idea here is that if there is no data in the cond value, do pass to not show the plot. However ever time I run this, the plot shows, even thought there is no data for it.

When i call the function i put in plot_timeseries(time=time_data, depth=depth_data temp=temp_data)

my aim is for only the temp data in this example to show, not a cond graph with no variables.

what i have tried is

if cond != []:
        plotting code
        plt.show()
else:
        print('there is no cond data')
        pass

and

plotting code
if cond == []:
    print('no cond data')
    pass
else:
    plt.show()

to no avail.

note that there are 4 other plots in this function i would like to do the same thing. thanks for any insight this community can give me.

Aucun commentaire:

Enregistrer un commentaire