1

I have a for loop that is generating from a zipped list time series line plots.

Right now I have it so it is generates a single plot in a window. When the user clicks to close, the next plot shows.

I want to make it so that it displays all these plots with their own respective axis and values in rows of three vertically stacked.

I attemped this with the below code with just single vertical stacking by trying to loop through '''ax''' but it is generating the same plot. It is iterating over the same data but I am not sure how to logically change it so it iterates over each plot.

for title,unit, y, x, in zip(NameData,UnitData,value_list,dates_list):
        if np.size(y) > 0:
            fig, ax = plt.subplots(10)
            fig.supxlabel('Time')
            try:
                fig.supylabel('Units:' + unit)
            except TypeError:
                pass
            for i in range(1):
                ax[i].plot(x,y)
                ax[i].set_title(title)
            plt.show()     
            plt.close()
        else:
            pass
NameData: [Dog,Cat,Mouse]
UnitData: [mm, cm, nm]
value_list: [[1,2,3],[4,5,6],[7,8,9]]
dates_list: datetime[[1/27/2012,1/28/2012,1/29/2012],[1/27/2012,1/28/2012,1/29/2012],[1/27/2012,1/28/2012,1/29/2012]]

1 Answer 1

3

Is this what you are trying to achieve?

fig, ax = plt.subplots(nrows=3, ncols=1, sharex=True)
fig.supxlabel('Time')
for i, (title, unit, y, x) in enumerate(zip(NameData,UnitData,value_list,dates_list)):
    ax[i].plot(x,y)
    ax[i].set_title(title)
    ax[i].set_ylabel(unit)
plt.tight_layout()

enter image description here

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

1 Comment

yes and +1 for optimizing - I adapted this to add more columns as well as keep the respective x axis

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.