Skip to main content

Matlab plot figure modifying tips pixed dpi relationship


Matlab  plot figure all basic operation
===========================

x = [1:5];
y = [7 8 1 9  10]

h =figure

plot(x,y)
hold on
plot(x, y+5);

% change axis properties

set(gca,'box','off'); % remove box around figure
set(gca,'FontSize',fontsize_tick-1); % set tick size in figure
set(gca,'LooseInset',get(gca,'TightInset'));  % if you want to remove space on right of figure
xlabel(commonLabelWindow,'fontsize' , fontsize_label);
ylabel('Average AT-skew','fontsize' , fontsize_label_special);
xlim ( [ min(myX)   max(myX)])
ylim ( [ min( [myY1  myY2  ])   max([ myY1  myY2  ])  ])



% change size of figure

http://www.mathworks.com/help/matlab/creating_plots/positioning-figures.html




%  set size of figure's "drawing" area on screen ( 5.5 cm  width ) by ( 4.0 cm height)

set(gcf, 'Units','centimeters', 'Position',[0 0 5.5 4.0])


% change resolution 600 dpi

http://www.mathworks.com/help/matlab/ref/print.html

set(gcf,'PaperPositionMode','auto'); % you MUST add this to make sure output wil'b same as screen
print('-depsc','skewAT.eps' , '-r600');
print('-dtiff','skewAT600.tif' , '-r600');


% save as file using default resolution

 saveas(h,'skewAT.eps','epsc2');
 saveas(h,'skewAT.fig','fig');
 saveas(h,'skewAT.png','png');



% close  figure

close(h);

end


% using transparent patch

[ciC_withRpt,bootstat] = bootci(noBootstrap, {myfnc,matCoding});
mypatchY = [ciC_withRpt(1,:)  fliplr(ciC_withRpt(2,:))]; 

% flip to make joining patch

mypatchX = [ myX fliplr(myX) ]; % flip to make joining patch
 

mypatch = patch(mypatchX , mypatchY,color_C_withRpt_patch,'edgecolor','none', 'FaceAlpha' , alphaVal );


% using transparent patch may overlap with axis;  border of figure disappear
 solution: shift camera little bit

ct = camtarget;
camtarget([ct(1)+0.001*ct(1) ct(2)+0.001 ct(3)]);





 http://www.mathworks.com/support/solutions/en/data/1-5TS5P4/index.html?product=ML&solution=1-5TS5P4

Solution:

This is an issue with the 'OpenGL' renderer installed in the system. When using transparency in a plot the figures renderer is automatically set to OpenGL. This renderer often clips the axes box and tick marks.

To work around this issue, you can make the axes box visible by slightly changing the camera target of the axes:
ct = camtarget;
camtarget([ct(1)+0.001*ct(1) ct(2)+0.001 ct(3)]);
To make the tick marks at the right side and top visible you can overlay another axes object with the same settings as the other axes, empty its ticklabels and set the axis locations to the right and top of the axes:
ax2 = copyobj(gca,gcf);
set(ax2,'XAxisLocation','top','XTickLabel','','YAxisLocation','right','YTickLabel','','Color','none')




% Determine image width by  Resolution at paper size

Very good tutorial :
http://auctionrepair.com/pixels.html

Input:
W = width of a printing area of a journal page (e.g. A4 W = 17.8 cm)
H = height of a printing area of a journal page (e.g. A4 H = 24 cm)
D = dots per inch (the required resolution )

Output:
Picture pixel and picture width

Calculation: 

given,

W = 17cm;
D= 600 dpi;

calculate: 

// change only width
Win = W/2.54;
imW = floor(Win*D);
n = 3; // No of figure per row
imW = floor(imW/n)*n;
imWi = imW/n;
im1 = imresize (im1Big, [NaN imWi]);

// change both width, height 
H = 24;
Hin = H/2.54;
imH = floor(Hin*d);
nV=5;
imH = floor(imH/nv)*nv;
imHi = imH/nv;
im1 = imresize(im1Big, [imHi imWi]);


Merging N figure in  rows( Our W=17.8 cm width of printable area for a journal page , n = 3 number of image per row)

function mymergeTanvir

im1Big = im2double (imread('skewCG_CPS.tif'));
im1 = imresize(im1Big, [NaN 1338]);
size(im1);
clearvars im1Big;

im2Big = im2double (imread('skewAT_CPS.tif'));
im2 = imresize(im2Big, [NaN 1338]);
size(im2)
clearvars im2Big;

im3Big = im2double (imread('skewCG_CPS.tif'));
im3 = imresize(im3Big, [NaN 1338]);
size(im3);
clearvars im3Big;


% [  im1 im2 im3;  im4 im5 im6]; % if you want 6 figures in 2 row
im = [im1 im2 im3 ]; % if you want 3 figures in 1 row

size(im);
imshow(im);
imwrite(im, 'test2.tif' ); % create the combined image

print -dtiff -r600 test.tif ; % export to disk at desired resolution
print -dpdf -r600 test.pdf ; % export to disk at desired resolution

% set(gcf, 'paperunits', 'centimeters', 'paperposition', [0 0 15 15]);
% the number after 'm' is magnification - quality of the pdf
% export_fig('combinedIm.pdf', '-m2', gcf);

end

Comments

Popular posts from this blog

MATLAB cross validation

// use built-in function samplesize = size( matrix , 1); c = cvpartition(samplesize,  'kfold' , k); % return the indexes on each fold ///// output in matlab console K-fold cross validation partition              N: 10    NumTestSets: 4      TrainSize: 8  7  7  8       TestSize: 2  3  3  2 ////////////////////// for i=1 : k    trainIdxs = find(training(c,i) ); %training(c,i);  // 1 means in train , 0 means in test    testInxs  = find(test(c,i)       ); % test(c,i);       // 1 means in test , 0 means in train    trainMatrix = matrix (  matrix(trainIdxs ), : );    testMatrix  = matrix (  matrix(testIdxs  ), : ); end //// now calculate performance %%  calculate performance of a partition     selectedKfoldSen=[];selectedKfoldSpe=[];selectedKfoldAcc=[];     indexSen=1;indexSpe=1;indexAcc=1;     if ( kfold == (P+N) )% leave one out         sensitivity = sum(cvtp) /( sum(cvtp) + sum(cvfn) )         specificity = sum(cvtn) /( sum(cvfp) + sum(cvtn) )         acc

R tutorial

Install R in linux ============ In CRAN home page, the latest version is not available. So, in fedora, Open the terminal yum list R  --> To check the latest available version of r yum install R --> install R version yum update R --> update current version to latest one 0 find help ============ ?exact topic name (  i.e.   ?mean ) 0.0 INSTALL 3rd party package  ==================== install.packages('mvtnorm' , dependencies = TRUE , lib='/home/alamt/myRlibrary/')   #  install new package BED file parsing (Always use read.delim it is the best) library(MASS) #library(ggplot2) dirRoot="D:/research/F5shortRNA/TestRIKEN/Rscripts/" dirData="D:/research/F5shortRNA/TestRIKEN/" setwd(dirRoot) getwd() myBed="test.bed" fnmBed=paste(dirData, myBed, sep="") # ccdsHh19.bed   tmp.bed ## Read bed use read.delim - it is the  best mybed=read.delim(fnmBed, header = FALSE, sep = "\t", quote = &q