I'm currently working on a study about fuel consumption. I have multiple .fig files that shows the trend of fuel consumption in L/100 Km versus Time. I have multiple cases showing the behavior of the plot under different conditions, and I wan't to show the differences between them. An example of the plot is shown below:
Is there anyway to stack plots from different .fig files in 1 .fig file?
Ideally, you'd want to generate those different plots using subplot.
Your exact question has been answered by ZiV in the mathworks forums:
One way to do this is to extract xdata and ydata from existing
figures, then re-plot these data in a new figure window as desired.
For example,
open('gugu.fig');
h_gugu=get(gca,'Children');
x_gugu=get(h_gugu,'XData');
y_gugu=get(h_gugu,'YData');
open('lulu.fig');
h_lulu=get(gca,'Children');
x_lulu=get(h_lulu,'XData');
y_lulu=get(h_lulu,'YData');
figure
subplot(121)
plot(x_gugu,y_gugu);
subplot(122)
plot(x_lulu,y_lulu)
saveas(gcf,'gugululu','fig')
Related
I'm doing numerics and I have an error plot made on two parameters, which means that I have a matrix where in the (i,j)-component I have the error made using two different specific values for the two parameters.
I used imagesc command in MatLab to obtain the following result:
The problem is with the colorbar: my values ranges from 1 to 10^(-16), so I need to do a logarithmic colorbar in order to see a right scaling in the "blue" part of the plot, since the values there can change of some orders of magnitude. Actually, I found lots of questions and answers, and I chose this one from MatLab community
So I substitute the parameter "L" in the linked code with
L = [1e-16,1e-15,1e-14,1e-13,1e-12,1e-11,1e-10, 1e-9, 1e-8, 1e-7, 1e-6,1e-5,1e-4,1e-3,1e-2,1e-1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1e0];
but what I obtain is the following:
and so now I can't see the changes in the upper triangular part of the table.
Does anyone has some idea on how to fix it in order to see better the changes in the yellow part?
EDIT:
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
The default graphs produced from matlab are very different from what I see in books. For example the image below looks visually pleasing. Can I change default settings of matlab to mimic this graphing style?
This question will refrain from lecturing the OP on best practices for graphics and simply attempt to answer the question as asked. I personally concur with a few of the concerns raised but leave it to the OP to seek out resources on data visualization and graphical aesthetics. (For the record, I'm not a fan of the chart.)
Resources:
The MATLAB Plot Gallery depicts a range of plots and adjustments that may help you. For high quality, professional looking graphs, scroll down to the Advanced Plots to see source code and the resulting figures.
Graphical overview of the Types of MATLAB Plots available.
You can also make a basic plot then use MATLAB's Plot Editor to customize the properties through the graphical interface. When done, click File-->Generate Code and you'll see one possible way to code that graph. This is helpful when you know how to do something through the interface but want to script it in the future.
Examples with code for Publication Quality Plots with Matlab
Mathworks blog on Making Pretty Graphs
Another example on Creating high-quality graphics in MATLAB for papers and presentations
I realize some of these links may eventually expire. Please feel free to comment if they do
Example:
I'm no expert. I learned everything in this answer from looking at the documentation, plot source code, and playing with the properties for the various plot components.
% Functions of Interest % MATLAB 2018a
fh=#(x) a + a*sin(b*x) + 1-exp(-b*x);
gh=#(x) a + (a/b)*cos(c*x);
a = 20;
b = .3;
c = .2;
% Plot
X = (0:.01:25)';
figure, hold on
p(1) = plot(X,fh(X),'r-','DisplayName','Excitation')
p(2) = plot(X,gh(X),'b-','DisplayName','Recovery')
% legend('show') % Optional legend (omitted here since we're adding text)
xlabel('X')
ylabel('Y')
title('Particle Displacement')
% Options
ha = gca;
box on
grid on
ylim([-80 100])
set(ha,'GridLineStyle','--') % use ':' for dots
t(1) = text(3.5,80,'excitation')
t(2) = text(12,20,'recovery')
for k = 1:2
p(k).LineWidth = 2.2;
t(k).FontWeight = 'bold';
t(k).FontSize = 12;
t(k).FontName = 'Arial';
end
Create a function which takes a matrix of data where each row represents a signal that you want to plot.
Define some styles you want to use for plotting. In your example plot, the first two would be 'bo' and 'rx'. Just iterate over your rows and plot each row with a different style followed by the command "hold on;"
function fancyplot(xaxis, matrix)
figure;
style = {'bo', 'rx', 'k.'}; # and so on
for r = 1:size(matrix, 1)
plot(xaxis, matrix(r,:), style{r});
hold on;
end
end
Write another script which you execute right after you plot or add it to the function above. In this script use the the following methods to control the limits of the axis
xlim
ylim
Set them to the min/max values of the data you plotted.
To add text to your plots use the Text command.
If you want to use these plots in publications be mindful of the fact that most publications are black and white and your graphs should be distinguishable event if they are not colored (I doubt the ones above would be). I always believed doing all formatting in code is a good idea without the manual tinkering around. Otherwise you might figure out that you have to update all 8 plots in your publication at 4 am shortly before you need to submit your paper. If you run some simulations and all formatting is in code you can simply execute your formatting scripts and save the plots automatically how to save a picture from code, preferably to the eps format.
I'm having some trouble in Matlab, and this might be more of a methodology/logic question.
So I have three netCDF files that I am loading into three separate matrices. Two of these matrices are values of a test run for two different experiments (all three files are gridded), and the other is the p-value of the data between the two experiments.
I want to create a new netCDF file that has the values of the difference between the two experiments if that particular grid has a pvalue <= 0.05.
I thought this would be fairly easy. Here is what I implemented:
%find the difference between experiments, averaged over the 3rd dimension
yr_diff = mean(mat_2012-mat_1980,3);
yr_diff(pvalue >= 0.05) = NaN;
final_grid = yr_diff;
And then I used a fairly straight forward netCDF exporting scheme. To my knowledge, the mat_2012 and mat_1980 matrices are organized in the same as the pvalue matrix.
This produces a sort of weird grid that doesn't really show anything. The first image below shows filled contours of the differences, with black contour lines where the areas are significant. The second plot shows filled contours of the netCDF file created with this logic, with the same significant contour lines.
So my question: Is the logic incorrect, and should I take a new direction? Is this something related to my exporting scheme? Or is this something else completely?
I'm just getting started with matlab and I'm trying to plot some graph with it.
The problem is I don't know how to get the average data out of 10 plot().
Can anyone guide me for it? Thank you :)
Assuming you don't have access to the original data you used for doing the plots:
plot_data = get(get(gca,'Children'),'YData'); % cell array of all "y" data of plots
average = mean(cell2mat(plot_data));
In order for this to work, you have to use this code right after doing the plots, that is, without plotting to any other figure (gca is a handle to the current axes).
Assume your data is stored row-wise in a m x n matrix A, with n columns corresponding to different values of the continuous error, and m rows corresponding to different curves. Then to inspect the mean over the curves just use
Amean = mean(A,1);
plot(Amean)
Please take a look at this link: it solve my problem getting the average plot.
https://www.mathworks.com/matlabcentral/fileexchange/27134-plot-average-line
After downloading the files just put those script on your working folder and add this line to your script.
plotAverage(gca,[],'userobustmean',0)
I have a text file with length and orientation of lines. I wish to plot rose diagrams of the orientations at length intervals of 2000m. My lengths go from 98m to 18000m. I do not use MATLAB often - only for very simple things such as plotting a rose diagram of the entire region. I am really lost when it comes to loops.
This is the what I have for the entire region. But I want it broken up into 10 plots. I can do this piece by piece but that will take me quite a while since I have to do this for several text files.
length=faults(:,4);
theta=faults(:,3);
radians=pi*theta/180;
rose (radians,60);
view(90,-90)
Thanks heaps!
EDIT: To better clarify: I wish to extract lines between 0-2000, 2000-4000. 4000-6000, etc. And for each of these intervals plot the orientation. Thanks
The best approach would be to use a for loop, see Mathwork's documentation on Flow Control. I'm not sure what your faults variable is, so I cannot give a complete example. Also, what do you need the variable length for? Anyway, this is roughly how you could proceed with the for loop:
thetas = ...; % matrix of thetas
for i = 1:size(thetas,2)
theta = thetas(:,i);
radians=pi*theta/180;
rose (radians,60);
end