Click here to Skip to main content
15,068,988 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code which gives me 4 individual live plotting graphs for 4 different sensors. But, I want them in a single frame using subplots. Pasting the piece of code which are plotting my graphs. How should I modify them for my output to be a subplots of 4 live graphs.

Python
def makeFigure(xLimit, yLimit, title):
    xmin, xmax = xLimit
    ymin, ymax = yLimit
    fig = plt.figure()
    ax = plt.axes(xlim=(xmin, xmax), ylim=(int(ymin - (ymax - ymin) / 10), int(ymax + (ymax - ymin) / 10)))
    ax.set_title(title)
    ax.set_xlabel("Time")
    ax.set_ylabel("Detector Output")
    ax.grid(True)
    return fig, ax

pltInterval = 50  # Period at which the plot animation updates [ms]
    lineLabelText = ['Detector A', 'Detector B', 'Detector C', 'Detector D']
    title = ['Detector A', 'Detector B', 'Detector C', 'Detector D']
    xLimit = [(0, maxPlotLength), (0, maxPlotLength), (0, maxPlotLength), (0, maxPlotLength)]
    yLimit = [(-1, 1), (-1, 1), (-1, 1), (-1, 1)]
    style = ['r-', 'g-', 'b-', 'y-']  # linestyles for the different plots
    anim = []
    for i in range(numPlots):
        fig, ax = makeFigure(xLimit[i], yLimit[i], title[i])
        lines = ax.plot([], [], style[i], label=lineLabelText[i])[0]
        timeText = ax.text(0.50, 0.95, '', transform=ax.transAxes)
        lineValueText = ax.text(0.50, 0.90, '', transform=ax.transAxes)

        anim.append(
            animation.FuncAnimation(fig, s.getSerialData, fargs=(lines, lineValueText, lineLabelText[i], timeText, i),
                                    interval=pltInterval))  # fargs has to be a tuple

        plt.legend(loc="upper left")
        plt.subplot(2,2,i)
    plt.show()

    s.close()


What I have tried:

I have tried editing this function with regular subplot commands but am getting many errors.
Posted
Comments
Richard MacCutchan 17-May-21 10:13am
   
"but am getting many errors."
Then you need to show the code, and the exact text of the errors.
Member 15203076 18-May-21 2:09am
   
Do you want see the whole code?
Richard MacCutchan 18-May-21 3:46am
   
Not unless it explains the problem. You need to understand that we have never seen this code before, we have no idea what it is supposed to do, or what it is doing wrong. You need to focus on those issues and provide clear details that we can work with.
Member 15203076 18-May-21 4:16am
   
Thanks man. Actually this code is working fine and is giving me 4 individual live plots. All am trying to do is placing them in a GUI. Before doing that am placing them in a subplot and then placing the entire canvas on a GUI. When am trying to edit this code for subplots, am getting errors and unwanted results. Any suggestions?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900