What code to make figure window fullscreen with subplot?

조회 수: 47 (최근 30일)
Théo Liénard--Mayor
Théo Liénard--Mayor 2019년 9월 25일
댓글: Rik 2019년 9월 30일
Hello everyone,
I am not a huge matlab user, I know the basics but I don't use it that much.
I created a script that opens a .txt file containing datas from an experiment, reads it, extracts the informations needed, plots 3 curves in a unique figures and then saves the figure created as a .jpg. It works fine, except it saves the Figure (3 subplots) as it appears in the "reduced" window, and I want to save it as the fullscreen window. Basically what I want to do is to add a line of code right before I save the picture that will make the Figure window fullscreen.
I saw some solutions like:
set(B,'PaperPositionMode', 'auto')
set(B,'Units','Normalized','Outerposition',[0 0 1 1]);
that work for only one plot, but when I tried to use it for my 3 plots it ended up making the third set of datas take the whole screen. Basically all I could find on internet doesn't seem to work for subplots.
Here is my code, do you have any suggestions?
Many thanks
clear
close all;
filename='24-09-2019_14-20-2001Theo_sample_100x_diluted_MD_ladder_in_240_mM_trisches_buffer_30_cm_50_um_capillary_25kV.dat.asc';% Your file to be plotted
data0=dlmread(filename,'\t');%get info that are on the text file
totaldatapointsRFU=data0(9,2);%infos needed to plot the datas
totaldatapointskV=data0(9,3);
totaldatapointsA=data0(9,4);
samplerateRFU=data0(8,2);
sampleratekV=data0(8,3);
samplerateA=data0(8,4);
xaxismultiplierRFU=data0(12,2);
yaxismultiplierRFU=data0(13,2);
xaxismultiplierkV=data0(12,3);
yaxismultiplierkV=data0(13,3);
xaxismultiplierA=data0(12,4);
yaxismultiplierA=data0(13,4);
dataRFU=data0(14:(13+totaldatapointsRFU),1)*yaxismultiplierRFU;%First set of datas located in the .txt file
timeRFU=linspace(0,totaldatapointsRFU/samplerateRFU,totaldatapointsRFU);%Time vector for the first datas
datakV=data0((14+totaldatapointsRFU):(13+totaldatapointsRFU+totaldatapointskV),1)*yaxismultiplierkV;%Second set of datas
timekV=linspace(0,totaldatapointskV/sampleratekV,totaldatapointskV);
dataA=data0((14+totaldatapointsRFU+totaldatapointskV):(13+totaldatapointsRFU+totaldatapointskV+totaldatapointsA),1)*yaxismultiplierA;%Thrid set of datas
timeA=linspace(0,totaldatapointsA/samplerateA,totaldatapointsA);
subplot(2,2,1)% Plot of the first set of datas
A=plot(timekV/60,datakV,'LineWidth',3);
xlabel('Time in minutes','FontSize',20,'FontWeight','bold','Color','k')%First argument is the x-axis name
xlim([0 1.1*max(timekV)/60])
ylabel('Tension in kV','FontSize',20,'FontWeight','bold','Color','k')%First argument is the y-axis name
ylim([1.1*min(datakV) 1.1*max(datakV)])
%set(A,'PaperPositionMode', 'auto')
%set(A,'Units','Normalized','Outerposition',[0 0 1 1]);
subplot(2,2,2)% Plot of the second set of datas
B=plot(timeA/60,dataA,'LineWidth',3);
xlabel('Time in minutes','FontSize',20,'FontWeight','bold','Color','k')%First argument is the x-axis name
xlim([0 1.1*max(timeA)/60])
ylabel('Current in µA','FontSize',20,'FontWeight','bold','Color','k')%First argument is the y-axis name
ylim([1.1*min(dataA) 1.1*max(dataA)])
%set(B,'PaperPositionMode', 'auto')
%set(B,'Units','Normalized','Outerposition',[0 0 1 1]);
subplot(2,2,[3,4]) %plot of the third set of datas
C=plot(timeRFU/60, dataRFU, 'LineWidth', 3);
xlabel('Time in minutes','FontSize',20,'FontWeight','bold','Color','k')%First argument is the x-axis name
xlim([0 1.1*max(timeRFU)/60])
ylabel('RFU','FontSize',20,'FontWeight','bold','Color','k')%First argument is the y-axis name
ylim([1.1*min(dataRFU) 1.1*max(dataRFU)])
%set(C,'Units','Normalized','Outerposition',[0 0 1 1]);
%set(C,'PaperPositionMode', 'auto')
set(gca,'FontSize',20)
%set(gca,'Units','Normalized','Outerposition',[0 0 1 1]);
title('100x diluted MD ladder in 25 mM LiAc buffer, 30 cm 50 µm capillary','FontSize',20,'FontWeight','bold','Color','k')%First argument is the title
filename1=erase(filename,'.dat.asc');%Saves the plot in a file with the same name but as a JPG
saveas(gcf,[filename1 '.jpg'])
  댓글 수: 2
Rik
Rik 2019년 9월 25일

So you want to maximize the figure before making the image?

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2019년 9월 25일
You can use my maximize FEX submission, and/or if you're using R2018a or later you can set the WindowState property (see the documentation for all the options: link).
set(gcf,'WindowState','maximized')
  댓글 수: 3
Théo Liénard--Mayor
Théo Liénard--Mayor 2019년 9월 30일
Here the modified code with your function:
clear
close all;
filename='19-09_2019_14_02_49_01_100x_diluted_MD_ladder_in_25_mM_LiAc_buffer_30_cm_50_um_capillary.dat.asc';% Your file to be plotted
data0=dlmread(filename,'\t');%get info that are on the text file
totaldatapointsRFU=data0(9,2);%infos needed to plot the datas
totaldatapointskV=data0(9,3);
totaldatapointsA=data0(9,4);
samplerateRFU=data0(8,2);
sampleratekV=data0(8,3);
samplerateA=data0(8,4);
xaxismultiplierRFU=data0(12,2);
yaxismultiplierRFU=data0(13,2);
xaxismultiplierkV=data0(12,3);
yaxismultiplierkV=data0(13,3);
xaxismultiplierA=data0(12,4);
yaxismultiplierA=data0(13,4);
dataRFU=data0(14:(13+totaldatapointsRFU),1)*yaxismultiplierRFU;%First set of datas located in the .txt file
timeRFU=linspace(0,totaldatapointsRFU/samplerateRFU,totaldatapointsRFU);%Time vector for the first datas
datakV=data0((14+totaldatapointsRFU):(13+totaldatapointsRFU+totaldatapointskV),1)*yaxismultiplierkV;%Second set of datas
timekV=linspace(0,totaldatapointskV/sampleratekV,totaldatapointskV);
dataA=data0((14+totaldatapointsRFU+totaldatapointskV):(13+totaldatapointsRFU+totaldatapointskV+totaldatapointsA),1)*yaxismultiplierA;%Thrid set of datas
timeA=linspace(0,totaldatapointsA/samplerateA,totaldatapointsA);
subplot(2,2,1)% Plot of the first set of datas
A=plot(timekV/60,datakV,'LineWidth',3);
xlabel('Time in minutes','FontSize',15,'FontWeight','bold','Color','k')%First argument is the x-axis name
xlim([0 1.1*max(timekV)/60])
ylabel('Tension in kV','FontSize',15,'FontWeight','bold','Color','k')%First argument is the y-axis name
ylim([1.1*min(datakV) 1.1*max(datakV)])
%set(A,'PaperPositionMode', 'auto')
%set(A,'Units','Normalized','Outerposition',[0 0 1 1]);
subplot(2,2,2)% Plot of the second set of datas
B=plot(timeA/60,dataA,'LineWidth',3);
xlabel('Time in minutes','FontSize',15,'FontWeight','bold','Color','k')%First argument is the x-axis name
xlim([0 1.1*max(timeA)/60])
ylabel('Current in µA','FontSize',15,'FontWeight','bold','Color','k')%First argument is the y-axis name
ylim([1.1*min(dataA) 1.1*max(dataA)])
%set(B,'PaperPositionMode', 'auto')
%set(B,'Units','Normalized','Outerposition',[0 0 1 1]);
subplot(2,2,[3,4]) %plot of the third set of datas
C=plot(timeRFU/60, dataRFU, 'LineWidth', 3);
xlabel('Time in minutes','FontSize',15,'FontWeight','bold','Color','k')%First argument is the x-axis name
xlim([0 1.1*max(timeRFU)/60])
ylabel('RFU','FontSize',15,'FontWeight','bold','Color','k')%First argument is the y-axis name
ylim([1.1*min(dataRFU) 1.1*max(dataRFU)])
%set(C,'Units','Normalized','Outerposition',[0 0 1 1]);
%set(C,'PaperPositionMode', 'auto')
%set(gca,'FontSize',15)
%set(gca,'Units','Normalized','Outerposition',[0 0 1 1]);
title('100x diluted MD ladder in 25 mM LiAc buffer, 30 cm 50 µm capillary','FontSize',15,'FontWeight','bold','Color','k')%First argument is the title
maximize(gcf)
%set(gcf, 'Position', get(0, 'Screensize'));
filename1=erase(filename,'.dat.asc');%Saves the plot in a file with the same name but as a JPG
saveas(gcf,[filename1 '.jpg'])
Rik
Rik 2019년 9월 30일
If I recall correctly I just made the font size smaller until the output matched what I needed when I ran into this issue with Octave. The renderer is not super well-documented in Matlab, but for Octave on Windows it's even worse. If you can get Java to work reasonably well, you can use the FEX submission by Yair Altman to get a capture of your screen, instead of relying on a re-rendered output.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bruno Luong
Bruno Luong 2019년 9월 25일
편집: Bruno Luong 2019년 9월 25일
Check out This thread hope it's not obsolete. If you run on Windows WindowAPI (Jan's reply) is the only one which makes real full-screen display (no border...)
  댓글 수: 2
Théo Liénard--Mayor
Théo Liénard--Mayor 2019년 9월 30일
Hello Bruno,
I did find this thread while looking for the solution before posting my question, I tried the different suggestions but it ended up not working for me, but maybe I didn't use the suggestions correctly.
Anyways, thank you for your help!
Bruno Luong
Bruno Luong 2019년 9월 30일
Here is the image I get win WinAPI (I have an old version, syntax might varies)
fullscreentest.jpg
close all
plot(rand(1,100))
WindowAPI(get(gcf,'Number'),'Position','full')
saveas(gcf,'fullscreentest.jpg')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by