Important: Please read the Qt Code of Conduct -

Problem with plotting multiple plots in the same MatplotlibWidget graph

  • Hi,

    I am new to both python and QT4 but have since a couple of weeks back been working on a software that will take user based input and present the results in the QT matplotlibwidget. I can currently present one plot at a time in the widget but have not been able to plot multiple plots in the same graph.
    Oddly enough I am able to achieve multiple plots in the same graph if I use a normal matplotlib window(not the widget) when I run the same code using instead of draw(). However when I call on the matplotlibwidget nothing appears in the plot.

    Here is the code that I can't get to run the way I would like:

    def plotRetained(self):
        i = 0
        colors = cm.rainbow(np.linspace(0, 1, len(Model.busSetDictionary)))
        for everySet in Model.busSetDictionary:
        #busSetDictionary is a dictionary containing dictionaries(busDictionary) which contains a list
            busDictionary = Model.busSetDictionary[i]
            data = {"x":[], "y":[], "label":[]}
            for label, coord in busDictionary.items():
            self.matplotlibwidget.axes.plot(data["x"], data["y"], marker='o', color = colors[i], markerfacecolor=colors[i], markersize=12)

    When I run this code only the last itteration of busDictionary will be plotted instead of all the busDictionaries.

    If anybody could help me identify the problem that would be greatly appreciated!

    Ps. There are 1500 lines of code so I can not post all of it but if anyone is curious about other parts of the code just let me know and I will post that too.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    This is a question you should rather bring to the Matplotlib folks.

    On a side note, unless you are locked to that version, please move to Qt 5. Qt 4 has reached end of life a few years ago.

  • The reason I asked you guys is that is seems specific to the QT MatplotlibWidget. Like I mentioned in the post I can achieve what I want in the normal Matplotlib Window but not in the MatplotlibWidget

  • Lifetime Qt Champion

    Well, that's the thing: the Qt MatplotLibWidget is still implemented by these guys hence my suggestion to ask them.

    You should also check whether you are using PyQt or PySide to see if it makes any difference. It should not but who knows.

  • Ahh I see. I'll check it out!

    Thanks for the suggestion. If you have any other ideas please let me know.

Log in to reply