I have a plot I get from matlab, with the x-axis ranging from 0 to 1864 values. I want to save this plot as a .png image without need to modify the original .fig file manually
My plot looks like this:
As you can see, the last two numbers are overlapping. The reason is that when matlab displays my image, the popup window is too small. I already tried to change the axes ratio using daspect, but it does not work.
What I think could work is to use the function truesize, my problem is that when I try to use it, I receive the following error:
No images or texturemapped surfaces in the figure.
My code looks like this:
x = rand (1864,1);
F = bar (x);
xlim ([0 1864]);
set(gca, 'XTick', sort([1864, get(gca, 'XTick')]));
truesize(1,[100 100])
Why does this happen? How can I fix this problem in order to save the images preventing x labels overlapping?
You could try rotating your x labels using the following code:
x = rand (1864,1);
F = bar (x);
xlim ([0 1864]);
set(gca, 'XTick', sort([1864, get(gca, 'XTick')]));
set(gca, 'XTickLabelRotation', 90)
Note that you can change the degrees to rotate to other number besides 90 if you wanted.
It gives you a plot that looks like this:
Related
I used matlab code.
img = imread('cmap3.png')
map = jet(256)
ind = rgb2ind(img,map)
colormap(map)
cm = colormap('gray)
image(ind)
Through above code, I got the .
I want to save just the gray scale image without any graduations and numbers on x,y axis.
How do I remove them and save gray scale image?
If you use imwrite, you won't save the axes' labels.
For actual plots, there exists a different solutions, eg. described here: set the axis to start at the very left bottom corner so that there is no space left for descriptions: set(gca, 'Position',[0 0 1 1]). Than you can even use print to save the image/figure.
I made a plot using
h = figure;
x = 1:0.1:13;
plot(x, x, [';straight line;']);
print(h, 'graph.eps', '-color', '-deps', '-F:16');
which gives me
I want to increase just the height of the plotting window. I added the pbaspect([1 2]); line:
h = figure;
x = 1:0.1:13;
plot(x, x, [';straight line;']);
pbaspect([1 2]);
print(h, 'graph.eps', '-color', '-deps', '-F:16');
but I get a messed up plot:
I then changed the F:16 to F:8
h = figure;
x = 1:0.1:13;
plot(x, x, [';straight line;']);
pbaspect([1 2]);
print(h, 'graph.eps', '-color', '-deps', '-F:8');
and it works, but the resulting file still has the white margins on the sides(which you can see if you see the image below separately):
I want the final eps file to have the plot without the white margins. How can I achieve this?
The images were converted from eps to jpg using "convert graph.eps graph.jpg". However, they are meant to be used in a LaTeX document as eps images.
If I understood your question correctly, try adding the -tight option to print:
`-loose'
`-tight'
Force a tight or loose bounding box for eps files. The
default is loose.
I have created a GUI which has 2 subplots.The first one display original image.
How can i do when i want to zoom in first subplot and then display it in second subplot? Thanks in advance
You can do that by copying the data from the first subplot to the second and setting the axis limits. Here's an example that doesn't use a GUI but should work the same way:
figure
% create two subplots
ax1 = subplot(2,1,1);
ax2 = subplot(2,1,2);
% display some data in the first subplot
axes(ax1);
imagesc(spiral(10));
% get the range of the axes in the first subplot
xLim1 = get(ax1, 'XLim');
yLim1 = get(ax1, 'YLim');
% Ask the user to zoom in. Instead of pressing
% enter, there could be a button to push in
% a GUI
reply = input('Zoom in and press enter');
% Get the new, zoomed in axes
zoomedXLim = get(ax1, 'XLim');
zoomedYLim = get(ax1, 'YLim');
% get the data from the first axis and display
% it in the second axis.
data = getimage(ax1);
axes(ax2)
imagesc(data)
% set the second axis to the zoomed range
set(ax2, 'XLim', zoomedXLim)
set(ax2, 'YLim', zoomedYLim)
title('zoomed image')
% return the first axis to its original range.
set(ax1, 'XLim', xLim1)
set(ax1, 'YLim', yLim1)
axes(ax1)
title('original image')
The resulting figure will look something like this:
I use the following lines of code to plot the images:
for t=1:subplotCol
subplot(subplotRow,subplotCol,t)
imagesc([1 100],[1 100],c(:,:,nStep*t));
colorbar
xlabel('X-axis')
ylabel('Y-axis')
title(['Concentration profile at t_{',num2str(nStep*t),'}'])
subplot(subplotRow,subplotCol,subplotCol+t)
hold on;
plot(distance,gamma(:,1,t),'-ob');
plot(distance,gamma(:,2,t),'-or');
plot(distance,gamma(:,3,t),'-og');
xlabel('h');ylabel('\gamma (h)');
legend(['\Theta = ',num2str(theta(1))],...
['\Theta = ',num2str(theta(2))],['\Theta = ',num2str(theta(3))]);
end
I get the following subplot with images:
As you can see the images in first row are now scaled equally on X and Y axis (Y axis is longer than the X-axis) even though the size of the image matrix is 100x100 for each image on first row.
Can someone help with how to make images in first row look like squares than rectangles which I get currently. Thanks.
Use the dataAspectRatio properties of the axes, and set it to [1 1 1]
%# create a test image
imagesc(1:10,1:10,rand(10))
%# you should use the handle returned by subplot
%# instead of gca
set(gca,'dataAspectRatio',[1 1 1])
Another method is to use the command axis equal
Regarding the size of different objects, you can set the exact position of each axes on the figure, for example for the first one use:
subplot(2,2,1); set(gca,'Position',[0.05 0.05 0.4 0.4])
Whilst using Matlab's GUIDE, I wish to plot a line onto an image. I managed to achieve this when I was using only one axis inside the GUI. However upon adding another axis the plot no longer overlays the image.
Initially the plot began to plot on the wrong axis and I realized I had forgotten to set the appropriate axis. However once I had selected the image axis for plotting on, the line which is to be plotted, doesn't lie on top of the image anymore, instead it just replaces the image with a graph of the line only.
My code:
imshow(img(k),'Parent',handles.display)
hold on
x1 = line(k).point1(1);
y1 = line(k).point1(2);
x2 = line(k).point2(1);
y2 = line(k).point2(2);
plot(handles.display,[x1 x2],[y1 y2],'Color','r','LineWidth', 2)
hold off
The code before I added the new axis was identical to above but with the handles.display parameter for the plot().
Any help would be greatly appreciated, thank you in advance.
When you call the HOLD function, you also need to specify the axis handle. Example:
%# create some axes
hAx1 = subplot(121);
hAx2 = subplot(122);
%# draw in first: image with line overlayed
I = imread('coins.png');
imshow(I, 'Parent',hAx1)
hold(hAx1,'on')
plot(hAx1, [1 100], [1 100], 'Color','r', 'LineWidth',2)
hold(hAx1,'off')
%# draw in second
surf(hAx2, peaks)