0

I am trying to use PyPlot to display multiple graphs in a single window. I can do that no problem with the following code:

def create_figure_one(self):
    plt.figure(1)
    plt.subplot(311)
    plt.plot_date(self.dates, self.PREC, '-', color='b')
    plt.title('Precipitation', fontsize=20)
    plt.ylabel('MM/DT', fontsize=15)
    plt.tick_params(axis='both', which='major', labelsize=10)
    plt.tick_params(axis='both', which='minor', labelsize=10)
    plt.grid()

    plt.subplot(312)
    plt.plot_date(self.dates, self.PET, '-', color='b')
    plt.plot_date(self.dates, self.AET, '-', color='r')
    plt.title('Evapotranspiration', fontsize=20)
    plt.ylabel('MM/DT', fontsize=15)
    plt.tick_params(axis='both', which='major', labelsize=10)
    plt.tick_params(axis='both', which='minor', labelsize=10)
    red_patch = mpatches.Patch(color='blue', label='Potential')
    blue_patch = mpatches.Patch(color='red', label='Actual')
    plt.legend(handles=[red_patch, blue_patch])
    plt.grid()

    plt.subplot(313)
    plt.plot_date(self.dates, self.Q, '-', color='b')
    plt.title('Flow', fontsize=20)
    plt.ylabel('CMS', fontsize=15)
    plt.xlabel('Time', fontsize=15)
    plt.tick_params(axis='both', which='major', labelsize=10)
    plt.tick_params(axis='both', which='minor', labelsize=10)
    plt.grid()

    plt.show()

This function gets called after clicking a button in my GUI. Similarly, I have another button in my GUI which calls another function:

def create_figure_two(self): 
    plt.figure(1)
    #UZTWC
    plt.subplot(611)
    plt.plot_date(self.dates, self.UZTWC, '-', color='b')
    self.title('UZTWC', fontsize=15)
    plt.ylabel('MM', fontsize=10)
    plt.tick_params(axis='both', which='major', labelsize=10)
    plt.tick_params(axis='both', which='minor', labelsize=10)
    plt.grid()

    #UZFWC 
    plt.subplot(612)
    plt.plot_date(self.dates, self.UZFWC, '-', color='b')
    self.title('UZFWC', fontsize=15)
    plt.ylabel('MM', fontsize=10)
    plt.tick_params(axis='both', which='major', labelsize=10)
    plt.tick_params(axis='both', which='minor', labelsize=10)
    plt.grid()

    #LZTWC 
    plt.subplot(613)
    plt.plot_date(self.dates, self.LZTWC, '-', color='b')
    self.title('LZTWC', fontsize=15)
    plt.ylabel('MM', fontsize=10)
    plt.tick_params(axis='both', which='major', labelsize=10)
    plt.tick_params(axis='both', which='minor', labelsize=10)
    plt.grid()

    #LZFPC 
    plt.subplot(614)
    plt.plot_date(self.dates, self.LZFPC, '-', color='b')
    self.title('LZFPC', fontsize=15)
    plt.ylabel('MM', fontsize=10)
    plt.tick_params(axis='both', which='major', labelsize=10)
    plt.tick_params(axis='both', which='minor', labelsize=10)
    plt.grid()

    #LZFSC 
    plt.subplot(615)
    plt.plot_date(self.dates, self.LZFSC, '-', color='b')
    self.title('LZFSC', fontsize=15)
    plt.ylabel('MM', fontsize=10)
    plt.tick_params(axis='both', which='major', labelsize=10)
    plt.tick_params(axis='both', which='minor', labelsize=10)
    plt.grid()

    #ADIMC 
    plt.subplot(616)
    plt.plot_date(self.dates, self.ADIMC, '-', color='b')
    self.title('ADIMC', fontsize=15)
    plt.ylabel('MM', fontsize=10)
    plt.tick_params(axis='both', which='major', labelsize=10)
    plt.tick_params(axis='both', which='minor', labelsize=10)
    plt.xlabel('Time', fontsize=10)
    plt.grid()
    plt.show()

But nothing happens. I don't get any errors in my terminal, my program doesn't terminate, and no window with my graphs appears. I can't see what differences between my two functions could possibly account for why the first is working and the second isn't.

self.dates:

    self.list_of_datetimes = []
    skipped_header = False;
    with open(data_file, 'rt') as f:
        reader = csv.reader(f, delimiter=',', quoting=csv.QUOTE_NONE)
        for row in reader:
            if skipped_header:
                date_string = "%s/%s/%s %s" % (row[0].strip(), row[1].strip(), row[2].strip(), row[3].strip())
                dt = datetime.strptime(date_string, "%Y/%m/%d %H")
                self.list_of_datetimes.append(dt)
            skipped_header = True

    self.dates = matplotlib.dates.date2num(self.list_of_datetimes)

If anyone has any insight it would be greatly appreciated.

1 Answer 1

1

I am not a smart man... I had "self.title" in my second figure where I should of have "plt.title". That fixed it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.