0

I am trying to make multiple plots within a for loop based on some condition and after the for loop terminates, I want to save the plot files. I can do this with MATLAB, but not sure how to do this in python. Here is a sample code in MATLAB:

A = [some 2d matrix]
B = [some 2d matrix]

[row, col] = size(A)
for ii = 1:row

        x = A(ii,:)
    y = B(ii,:)
    
    if (some condition)
        figure(1)
        plot(x,y)
        hold on
        
    elseif (some condition)
        figure(2)
        plot(x,y)
        hold on
        
    elseif (some condition)
        figure(3)
        plot(x,y)
        hold on
        
    else
        figure(4)
        plot(x,y)
        hold on
    end
end

figure(1)
xlabel(...)
ylabel(...)
legend(...)
saveas()

figure(2)
xlabel(...)
ylabel(...)
legend(...)
saveas()


figure(3)
xlabel(...)
ylabel(...)
legend(...)
saveas()

figure(4)
xlabel(...)
ylabel(...)
legend(...)
saveas()

I want to do this in python, please help me through this.

Thank you.

I tried some matplotlib pyplot, but it does not seem to fulfill my requirements.

Khalid
  • 1
  • 1
  • 1
    Seems like you understand the concept. You can start working on your Python plot, and ask specific questions when you are stuck somewhere. You should not expect others to write you a complete code in Stackoverflow. Please check https://stackoverflow.com/help/how-to-ask. – Kani Jan 23 '23 at 18:25
  • Does this answer your question? [Save plot to image file instead of displaying it using Matplotlib](https://stackoverflow.com/questions/9622163/save-plot-to-image-file-instead-of-displaying-it-using-matplotlib) – Woodford Jan 23 '23 at 18:47

0 Answers0