Home > OS >  Drop down menu for the graph
Drop down menu for the graph

Time:12-03

I am new to python and I'm trying to make a drop down menu for this graph that shows temperatures at different times of day.The datas are imported from a csv file . Below is the code:

import csv

import matplotlib.pyplot as plt 
 
x=[]
 
y=[] 

z=[]
 
w=[] 

class grafice_statice():

    def run(self):
        with open('temperatura.csv', 'r') as csvfile:
            date = csv.reader(csvfile, delimiter=',')
            for row in date:
                try:
                    y.append(float(row[0]))
                    z.append(float(row[1]))
                    w.append(float(row[2]))
                    x.append(row[3])
                except Exception as e:
                    pass

        
        plt.figure(1)
        plt.plot(x,z, color='g', linestyle='dotted', marker='o', label='Temp 2(°C)!')
        plt.plot(x,y, color='m', linestyle='solid', marker='P', label='Temp 1(°C)!')
        plt.plot(x,w, color='r', linestyle='dashdot', marker='D', label='Temp 3(°C)!')

        plt.xlabel('Timpul')
        plt.ylabel('Temperatura(°C)')
        plt.title('Temperatura in functie de timp', fontsize = 18)
        plt.legend()

        plt.xticks([0,50,99])
        plt.ylim((-5,5))
        plt.show()
             
    grafice_stat=grafice_statice()
    grafice_stat.run()

How can I do this?

CodePudding user response:

If I understand your question correctly, you are trying to set up a dropdown menu to let the user choose which temperature plot to display. One way to do this is to use the ipywidgets Dropdown function. More info about it can be found enter image description here

When "Temp2" is selected:

enter image description here

  • Related