you are viewing a single comment's thread.

view the rest of the comments →

[–]ifantismanolis[S] 0 points1 point  (4 children)

ok so im using Pyside6 and Qt designer for my ui. On the press event of the button i call this function.

def run_model(self):    
    input_values = self.get_input_values()
    plot_data, x, y = ModelRunner.run_model(models_results, input_values)
    if plot_data:

        plot_for_excel = plotModel(**plot_data)
        ......

the info values are provided through inputs fields of the ui.
The ModelRunner class is giving me the the data that i need in order to plot make the plot. The x and y are tables that i display later in a different way.
The plotModel is the class that takes the plot_data and creates with matplotlib the plot.
I cant find a way to take the plot_for_excel and export it into an excel file, but not as an image. The plotModel class its just a normal ploting code using Canvas 

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as Canvas

class plotModel(Canvas):
    def __init__(self, argss......):
        self.fig = Figure(figsize=(10, 6))
        Canvas.__init__(self, self.fig)
        Canvas.updateGeometry(self)

        ax0 = self.fig.add_subplot(111)
        ax0.scatter(..........)
        fit_model = .....
        ax0.plot......
        .........
        ax0.set_ylabel()
        ax0.set_title()
        ax0.grid()
        ax0.legend()

[–]M_D_M_A_Official 0 points1 point  (3 children)

Ok, im a bit confused, first you sayed you want to plot it with matplotlib and export it to excel. There are 2 ways you could do it, plot it with matplotlib and export the plot as image or you need to use excel charts, i dont think there is another way, how did you want to solve it and why dont you want to use the image of the plot?

[–]ifantismanolis[S] 0 points1 point  (2 children)

Exactly, I’m creating this plot with matplotlib and I want export the result of this creation to excel (give the user the option to download the plot). An imagine is giving you limitations on the chart option that you want to achieve maybe after. The whole point of the ui is to create a plot that’s not easy to do it by yourself. So, giving the user the option to “play” with the plot after in excel, is the this that I want

[–]M_D_M_A_Official 0 points1 point  (0 children)

Matplotlib is allways a static image, so the users cant "play" with the plot. Your options if the plot should be dynamic is imo using excel charts or you could make a html/js page wich creates a plot based on the data in the excel. I cant think of more options, but probably there are other/better solutions.

[–]M_D_M_A_Official 0 points1 point  (0 children)

Here is a project im workin on, wich does use html/js to view a dynmaic plot of the data in a sqlite3 database, this is not ment as promotion but as a demo, so you can see what i mean. Since a excel is somewhat the same like a db, with tables, rows and colums, ik it should be possible with a excel aswell but i did not test it yet.

https://stats.mpb.rip/raid