What code to make figure window fullscreen with subplot?

48 ビュー (過去 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?

Théo Liénard--Mayor
Théo Liénard--Mayor 2019 年 9 月 25 日
Yes exactly

サインインしてコメントする。

採用された回答

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 Center および File ExchangeFilter Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by