matlab-figure

Add custom legend without any relation to the graph

孤街醉人 提交于 2019-11-28 08:59:18
I wish to insert a legend that is not related to the graph whatsoever: figure; hold on; plot(0,0,'or'); plot(0,0,'ob'); plot(0,0,'ok'); leg = legend('red','blue','black'); Now I wish to add it to another figure: figure; t=linspace(0,10,100); plot(t,sin(t)); %% ADD THE LEGEND OF PLOT ABOVE This is how I have solved this problem in the past: figure t=linspace(0,10,100); plot(t,sin(t)); hold on; h = zeros(3, 1); h(1) = plot(NaN,NaN,'or'); h(2) = plot(NaN,NaN,'ob'); h(3) = plot(NaN,NaN,'ok'); legend(h, 'red','blue','black'); This will plot the additional points, but because the coordinates are at

How to avoid image display artifacts in Matlab?

Deadly 提交于 2019-11-28 07:57:55
问题 When I display a bitmap image using image in a Matlab figure window, I'm experiencing strange artifacts: What I'm referring to are the cross-shaped structures which are particularly visible at the edges of the brain slice, but present throughout. These structures are not in the underlying image data, which are exactly identical to those in this image: I assume the artifacts have to do with the slight rescaling that is necessary to match the image to the given axes size. Does someone have an

Remove only axis lines without affecting ticks and tick labels

丶灬走出姿态 提交于 2019-11-28 07:48:30
Is there a way to remove only the axis lines in the Matlab figure, without affecting ticks and tick labels. I know that box toggles the upper and right axes lines and ticks and that works perfectly for me. But my problem is that I want eliminate the bottom and left lines (only lines!) but keeping the ticks and tick labels. Any tricks? There is another undocumented way (applicable to MATLAB R2014b and later versions) of removing the lines by changing the 'LineStyle' of rulers to 'none' . Example: figure; plot(1:4,'o-'); %Plotting some data pause(0.1); %Just to make sure that the plot is made

In MATLAB, how does one clear the last thing plotted to a figure?

馋奶兔 提交于 2019-11-28 07:26:19
问题 In MATLAB, I plot many different vectors to a figure. Now, what I would like to do is simply undo the last vector that I plotted to that figure, without clearing everything else. How can this be accomplished? Can it be accomplished? Thanks Edit: figure(1); clf(1); N = 100; x = randn(1,N); y = randn(1,N); z = sin(1:N); plot(x); hold on; plot(y,'r'); plot(z,'k'); Now here, I would like to remove the plot z, which was the last plot I made. 回答1: If you know before plotting that you want to remove

Matlab update plot with multiple data lines/curves

倾然丶 夕夏残阳落幕 提交于 2019-11-28 05:23:05
问题 I want to update a plot with multiple data lines/curves as fast as possible. I have seen some method for updating the plot like using: h = plot(x,y); set(h,'YDataSource','y') set(h,'XDataSource','x') refreshdata(h,'caller'); or set(h,'XData',x,'YData',y); For a single curve it works great, however I want to update not only one but multiple data curves. How can I do this? 回答1: If you create multiple plot objects with a single plot command, the handle returned by plot is actually an array of

Exporting figures as vector graphics in .pdf-format using HG2-Update and 'painters' renderer is not working properly

萝らか妹 提交于 2019-11-28 05:18:36
问题 I'm using the still undocumented HG2-Update to create my MATLAB plots, because they just look that much nicer. (Source: Yair Altman) Actually, using the current version Release 2013b it works quite nicely and there are not much issues. Except one wants to export the figures as vector graphics (renderer: '-painters' ), especially as pdf . I use the commands: saveas(gcf,'test.pdf','pdf') or print(gcf,'test.pdf','-dpdf') There are rendering issues, the print does not contain the whole figure and

Changing Fonts Size in Matlab Plots

感情迁移 提交于 2019-11-28 03:05:29
I want to change Font Size for xlabel , ylabel , axis size, legend font size a.k.a everything at once, is this possible? By default, font is Helvetica 10. Is there way to change this? I want to use 'FontSize',14, for x or y labels. Jonas's answer is good, but I had to modify it slightly to get every piece of text on the screen to change: set(gca,'FontSize',30,'fontWeight','bold') set(findall(gcf,'type','text'),'FontSize',30,'fontWeight','bold') If you want to change font size for all the text in a figure, you can use findall to find all text handles, after which it's easy: figureHandle = gcf;

3D scatter plot with 4D data

前提是你 提交于 2019-11-28 02:23:23
I need to plot a 3D figure with each data point colored with the value of a 4th variable using a colormap. Lets say I have 4 variables X,Y,Z and W where W = f(X,Y,Z). I want a 3D plot with X, Y, and Z as the three axis. The statement scatter3(X,Y,Z,'filled','b') gives me a scatter plot in 3D but I want to incorporate the value of Z in the graph by representing the points as an extra parameter (either with different areas :bigger circles for data points with high value of Z and small circles for data points with low value of Z or by plotting the data points with different colors using a

Multiple colors in the same line

守給你的承諾、 提交于 2019-11-28 02:07:19
I would like to plot a sine curve in Matlab. But I want it blue for the positive values and red for the negative values. The following code just makes everything red... x = []; y = []; for i = -180 : 180 x = [x i]; y = [y sin(i*pi/180)]; end p = plot(x, y) set(p, 'Color', 'red') Plot 2 lines with different colours, and NaN values at the positive/negative regions % Let's vectorise your code for efficiency too! x = -pi:0.01:pi; % Linearly spaced x between -pi and pi y = sin(x); % Compute sine of x bneg = y<0; % Logical array of negative y y_pos = y; y_pos(bneg) = NaN; % Array of only positive y

How to hold a plot when using plot3 in matlab?

可紊 提交于 2019-11-28 01:46:35
问题 This works as I expected: for i=1:100 hold on; plot(i,i^2); drawnow; end Ploting the points as they come in the same figure. This on the other hand, doesn't: for i=1:100 hold on; plot3(i,i^2,sqrt(i)); drawnow; end; Since it does not show a 3d plot of the points, it only shows the projection of them in the xy plane. Somehow the hold on statement messes up with plot3. How can I obtain results that are analogous to the 2d case when using plot , in the 3d case, when I have points in several 3d