I have taken readings on my software defined radio. I have three quantities, frequency, power and error rate. I would like to keep frequency on my x-axis as the latter quantities are measured with respect to frequency. Now I need to plot them on a single curve so that i can see frequency vs power and frequency vs error rate in one shot. I have been looking at matplotlib for quite some time but I see the 3d scatter plots and they seem to not convey the picture i want. So my question is
Is 3d plot useless in my case and I better plot 2 graphs and join the y axes of both graphs together so that I could see both the graphs on top of each other.
Is there a way in python or matlab such that you plot a 3d curve and then if you move the cursor you can see frequency vs power and if you move the cursor the other way you can see frequency vs error rate.
Any other ideas on how i can represent my readings better will be helpful.
When two sets of data share the same dependant variable (x-axis), it is common in scientific literature at least to plot them both in the following manner to save space:
This is preferred to twining the xaxis which can cause confusion for some people. It works especially well if features are to be compared.
This plot was generated using:
import pylab as py
x = py.linspace(0,10,1000)
y = py.sin(x)
z = py.sinc(x)
ax1 = py.subplot(211)
ax1.plot(x,y)
ax1.set_xticklabels([]) # Remove the xticks from the top figure
ax1.set_yticks(ax1.get_yticks()[1:]) # Stops the y axis overlapping
ax2 = py.subplot(212)
ax2.plot(x,z)
py.subplots_adjust(hspace=0.0)
py.show()
I believe there is a better way to remove the xticklabels but I can't remember it at the moment. Be careful not to just py.set_xticks([]) as if you then ask for a grid the top plot has no ticks.
Related
Is it possible to graphically represent linear transformations in MATLAB like the one shown below?
In particular, I'm looking for a way to represent the way a coordinate grid might become squished, stretched, or rotated after a matrix multiplication has been performed. I've tried using meshgrid(x,y) to plot the grid but I've been having trouble getting it to display properly. Ideally, it would be nice to see the way that the transformation acts on a unit square (and, if possible, to see the transformation being performed in a continuous fashion, where you can see the graphs morphing into each other). However, I'm willing to sacrifice these last two requirements.
Here is the code I have used so far:
x = -10:2:10;
y = -10:2:10;
[X,Y] = meshgrid(x,y);
plot(X,Y)
For some reason, only vertical lines have been plotted. (The documentation says it will display a square grid.)
please read the plot doc.
the problem is that what you are doing is trying to plot mash matrixes in a plot not by using mesh or something like that.
you may find this very helpful.
I am working with a data stream and for different time points in this stream I have density estimates over a fixed set of X values.
Each of these sets of estimates would look something like this
I'd like to plot multiple curves like this sideways, similar to how it's done in this answer
I've looked through the documentation regarding plotting but didn't find a straight-forward solution for it.
While it's easy to turn such a plot sideways by simply switching the axes, I didn't find a possibility to offset this from the Y-axis
Does anyone have an idea how to tackle this?
Instead of plotting
plot(x,y)
plot
plot(k+y,x)
where k is the location of the plot along the x axis (2 or 4 in your example).
I am trying to write a MATLAB script to give me a contour map. The contour map must be created from inputs that I generated from 100 images.
The story is like this:
I have 100 images on which I ran an image processing algorithm for optimization. Now, I got their energy curves. So, I have 100 energy curves. I want to create a contour map that will show me where the points are denser on the plot. (the energy curves are plotted as energy vs. iteration with fixed number of iterations)
The following is my variable:
energy(iteration,numImages)
Hope I explained it well.
Thanks in advance.
I interpret your question to boil down to how can I create a surface plot with colors according to the energy found in energy. I would solve this by using the contour function with a grid generated using meshgrid. If each image is described in 1000 data points with 100 files the plot can be generated as follows:
% using stuff as random junk instead of energy
numPoints = 1000;
numFiles = 100;
stuff = rand(1000,100); % replace with actual information
[X, Y] = meshgrid(1:numFiles, 1:numPoints);
contour(X,Y,stuff);
You can also create a 3D surface plot using surf and the same logic.
From what i see of you graph (and using the comments also), one possible way is to use plot3 to plot a line in 3D for every plot.
For doing so, you can use something like this code:
x=(0:0.01:1)';
aexp=zeros(100,numel(x));
hold on
for ii=1:100;
% aexp(ii,:)=exp((-x+ii/10)); %exponential
aexp(ii,:)=exp(-(x-ii/100).^2); %~gaussian
% aexp(ii,:)= x*ii; %linear increase
plot3(x,aexp(ii,:),ii*ones(1,numel(x)));
end
% set(gca,'yscale','log'); % uncomment if you need logscale.
giving
I have a few options of plot. It always plot from the XY view. I changed by hand, but you can use the view command. Notice that i used a simple counter to make the spacing in the z direction.
In a similar manner, you can plot using the contour. For my code, after the data have been generated in the for loop, remove/comment the plot3 and add:
contour(aexp) %outside the for loop,
giving
Notice that i have not really take care what i'm plotting. You can find more info on contour in the Matlab page .
You commented that the x-axis should be number of iterations, y-axis should be energy and z-axis should be the information containing how many lines are passing through from some areas. For this, make a qq variable, being it qq=number_of_lines(number of iterations,energy) . Make a discrete grid for the energy if you don't have one. Number of iterations is probably discrete anyway. The function is you who need to devise, but i would go for something which checks the number of lines for every energy and every iteration. In this case you will have the z-function that depends on y and x, that is the case to use contour or surface.
My function above make a line for every ii point, to have a 3d function. An edition for another extra loop is not hard. Just remember to have the same regular grid for every point, otherwise you will have trouble.
I need to plot two plots on same figure in MATLAB.
The maximum and minimum values in both the data samples have large variation, which I am unable to plot by taking same y-axis limits.
I do not wish to use two scales as explained in other Overlaying two axes in a Matlab plot but need to use a single y-axis and get the solution.
I tried the code:
x_axis_X = 1:length(S);
y_axis_Y = 1:length(N);
ylim([-1204200 -1841.6])
set(gcf,'color','w');
plot(x_axis_X, S,'o-', y_axis_Y, N, 'x-');
The result is as shown in the plot where one data sample is plotted without proper y-axis range.
The y limits for first data sample is -1204200 to -1841.6 and for the second it is -489429345.5 to -10408189.43.
How should be the ylim defined to fit both plots in the same figure?
I appreciate your inputs. Thank you.
In older versions of MATLAB use the function plotyy. In more recent versions of MATLAB use yyaxis. The following is the example from the documentation:
x = linspace(0,10);
y = sin(3*x);
yyaxis left
plot(x,y)
z = sin(3*x).*exp(0.5*x);
yyaxis right
plot(x,z)
ylim([-150 150])
I tried the idea of scaling one dataset so that it has a similar magnitude as the other data set. Here, I multiplied one dataset by 100 (or any suitable scaling parameter), and then it will be similar in size to the other data set. In order to clearly mention which data has been scaled in the graph I used the legend.
plot(x,data1,x,100*data2)
legend('data1','100*data2','location','southeast')
Thank you.
Scaling is not the best option, as you may need to work with the data later. Also does not work if for instance, you need a log scale.
Matlab has a few ways to deal it with. I particularly like to use a new axes in the figure, as i have done in the example below.
Just in case, you also found this answer in a simple google search!
Code:
a=1:10;
b=(10:-1:1)*100;
x=1:10;
hold on
plot(x,a,'b')
pax1=get(gca,'Position'); %get axis position
ax2 = axes('Position',pax1); %create a new axis
plot(ax2,x,b,'r') %plot new data
set(ax2, 'Yaxislocation','right',...
'color','none') % set it transparent and to the right
I am trying to program a matlab code in R2012a that will allow a color representation of temperature change on a surface based on different corresponding height and temperature measurements. Then end goal would be to combine multiple images together to get some sort of a jpeg. The temperatures I recorded were time specific which is why it would be beneficial in the end to have a visual depicting this temperature change over time.
It has been a little bit of time since I have used matlab, and I have never created something This complicated. It has me a little over whelmed and wondering where to start.
Thanks for any and all advice!
You might want to look at the avifile documentation for details on how to create a movie from a series of frames, there is a nice example that should make it clear enough.
Now to generate the frames needed for the avi file. Here, the meshgrid and surf functions come in handy. meshgrid generates two coordinate matrices with x and y coordinates for every point on your plate, surf then allows you to plot a surface with colors given by the temperatures at these positions. For example:
[x,y] = meshgrid(1:5,1:10) % generate a 10*5 plate with step size 1
z = rand(10,5) % height of the plate for a given position
c = rand(10,5) % color values, these should be your (time-dependent) temperatures
surf(x,y,z,c)
It is not clear to me whether you actually have a curved surface (requiring three coordinates to define each position), or just a simple plate. If it is just a simple plate, you can just set z = ones(size(x)) to obtain an uniform height.