Say I have a velocity field given by u = (y^3, 0, 0). What is the simplest way of plotting the vorticity of this field w = (3y^2, 0, 0) in Maple over the domain x in [-3, 3], y in [-3, 3]?
You can use the plots:-fieldplot3d command for a 3D plot (or the plots:-fieldplot command for a 2D plot).
There are several options which affect the look and feel, sizing and number of the arrows, etc.
For example,
plots:-fieldplot3d([0,0,-3*y^2], x=-3..3, y=-3..3, z=-10..10,
grid=[4,8,2], arrows=`3-D`,
fieldstrength=log[1.2], orientation=[43,66,0]);
You can use the plots:-display command to combine several such plots, where each has its own color say.
Related
I have several thousands of points to plot (about 10k) and I would like to plot them with Matlab but deciding a diferent size for each of the points (and a different color if possible). I tried to make a scatter plot for each point, but it is extremely slow compared to a single scatter call for all the points. Is there a way to plot several points in Matlab with different properties for each point, that works in a reasonable amount of time?
In case it is not possible to do it with Matlab, is there a way to do it with gnuplot?
scatter(x, y, a, c) takes arguments x and y, and then a for size, and c for colour. a can either be a single scalar, or a vector with a size for each (x,y) point. c can be an RGB triplet, or a vector, the same size as x and y. For example:
x = 1:4;
scatter(x, x, 10*x, x);
results in
So in your case, perhaps
scatter(xData, yData, [], 1:10000)
will result in your data having a different colour determined by its position in the data array.
For gnuplot it's easy, suppose you write your datafile with 3 columns, all you have to do is
plot 'data.dat' u 1:2:3:3 with circles lc palette
HERE you can find some examples (for help type help circles).
If you want just what is called variable pointsize (pointsize is not related to the real axis) you can use:
plot 'data.dat' with points ps variable pt 7
HERE you can find some examples (for help type help pointsize).
For gnuplot you can combine pointsize variable and linecolor variable or linecolor palette:
set xrange [0:10]
set samples 21
plot '+' using 1:1:(0.2*$1):1 with point pointsize variable linecolor palette pt 7 notitle
What I want to do is very simple, I just cannot seem to get MATLAB to do it. I would like to plot contours using my 2D data set.
My data set is large; 2 x 844240. I can do a scatter plot just fine,
scatter(Data(1,:), Data(2,:));
Reading through the forums I found Scatter plot with density in Matlab, where a hisogram was plotted. This would suffice, however, I would like to overlay the plots.
The issue is that they have different axis, my scatter data has an axis of [0 0.01 0 2500]; whereas the histogram is [0 100 0 100].
Is there a way to change the axis values of the histogram without modifying the image?
Thanks!
If I understand correctly, you are using hist3 to construct a histogram and then using imagesc to plot it. You can use the second output argument of hist3 to get the histogram bin centers, and then pass those on to imagesc, e.g.
nBins_x = 100;
nBins_y = 100;
[counts, bin_centers] = hist3(Data, [nBins_x nBins_y]);
x_bin_centers = bin_centers{1};
y_bin_centers = bin_centers{2};
imagesc(x_bin_centers, y_bin_centers, counts)
A couple other notes:
In your case, you will need to transpose your [2 x N] matrix when passing it to hist3, which expects an [N x 2] matrix.
imagesc puts the first axis (which I've been calling the "x" axis) on the vertical axis and the second on the horizontal axis. If you want to flip it, you can use:
imagesc(y_bin_centers, x_bin_centers, counts')
If you want to specify the histogram bins explicitly (e.g. to match your scatterplot) you can specify that in the arguments to hist3:
x_bin_centers = linspace(0, .01, 100);
y_bin_centers = linspace(0, 2500, 100);
counts = hist3(Data, {x_bin_centers, y_bin_centers};
And if you want a contour plot, you can use (note that contour takes the axes arguments in a different order than imagesc):
contour(x_bin_centers, y_bin_centers, counts');
If you are unhappy with the jaggedness of the contours, you may consider using a kernel density estimate instead of a histogram (check out ksdensity) (oops, looks like ksdensity is 1-D only. But there are File Exchange submissions for bivariate kernel density estimation).
In MATLAB, I have an existing set of values for X,Y where X = [0,1,2, ... 255], and Y is in the range of -5 to 4.
When I plot this graph MATLAB, obviously interpolates these values.
I require to increase the resolution of the X-axis to X = [0, 0.25, 0.5, 0. 75, 1 .... 254.75, 255].
I am not looking for a simple averaging kind of operation. Rather I want it to be as good as MATLAB which does it very smoothly. Please guide me.
A few things to know:
Matlab doesn't interpolate if you haven't made it interpolate. The figure you see is scalable, so there is no interpolation, at most a line connecting between adjacent dots.
If you want to interpolate just use interp1....
fore example,
Xnew= 0:0.25:255;
Ynew=interp1(X,Y,Xnew,'spline');
plot(Xnew,Ynew);
should do.
I'm trying to plot many 2D plots (x,y).
But...
each 2D plot is for a constant z.
So really my data is (x,y,z) but not z(x,y), which I believe are the requirements for using the "surf" command.
Could anyone help with this?
Example,
x = velocity
y = drag
I have multiple runs of y(x) for a constant temperature, z.
I just want to plot each (x,y) along a 3rd axis, temperature z.
Ideally I'd also want some sort of contour between the (x,y) plots so I can show the peaks/troughs etc.
Any help would be great.
If the runs are not independent (there is some trend over multiple runs) then it may make sense to use surf. You then need to construct your data such you have an X,Y, and Z - in this case I'd suggest you use the drag measurements as your Z (height).
Assuming that you have all the drag/velocity data in drag and velocity which are both of size [data points x number of runs]:
% construct matrix of run numbers
runs = repmat(1:numruns, [1, datapoints]);
runs = reshape(runs, datapoints, numruns);
% plot and label
surf(runs,velocity,drag);
xlabel('runs')
ylabel('velocity')
zlabel('drag')
I am trying to plot on the same figure the evolution of a function f, with argument x in ]0,1]. I would like to see both the evolution of f far away from 0 and close to 0, on the same figure, with one x axis.
For now I only have two different figures, one using plot with x=[0.1 ... 1], and one using semilogx with x=[1e-9 1e-7 1e-5... 0.1]. I would like to have both graphs on the same figure, with the x axis being logarithmic at the beginning, then linear after a certain x0 (let's say x0=0.1).
I do not want something using plotxx since I want only one x axis.
Do you know if this is possible?
Thank you for your time and help.
Just plot your y vector without specifying the x vector, this will get you a uniformly spaced plot, then use XTick and XTickLabel to make it work. For example,
x1=logspace(-10,-1,10);
x2=linspace(1,10,10);
y1=x1.^0.25;
y2=1./x2;
plot([y1 y2],'-x')
xlabels=num2cell([x1 x2]);
set(gca,'XTick',1:numel(x1)+numel(x2),'XTickLabel',xlabels)
If you want to use Latex to format tick labels, you'll need to download a function from the Matlab File Exchange.