I have this x y data:
I would like to increase the density of points by closing small gaps. How do i go about. I still want to preserve the structure of the points.
It depends on what you mean by 'closing gaps'.
if you mean that you want to make the data seem more grouped without actually adding more data points, then you might find the 'LineWidth' argument to be useful. If used currectly it increases the width of each marker in the scatter plot, which will make the data seem more grouped and with less gaps.
to use it, write the scatter code line as follows:
scatter(X, Y, 'LneWidth', width_number)
replace 'width_number' with different values and see the effect.
Related
I have a dataset that contains many symbol size data. However, the range of this symbol size dataset may be too large ( larger than 100k or smaller than 10). As a result, in the scatter plot, the size of the dots will vary greatly, and even interfere with the X-axis and Y-axis. How to make these dots as small as possible without affecting the view?
I try to use a function like sqrt() function to deal with it, but it does not work.image1
{
name: values_entity[i],
type:'scatter',
data: data[i],
symbolSize: Math.sqrt(symbolsize[i]),
color : '#e8a435'
}
In general you need to use proportionality but if you don't want to compute coefficients by yourself try to d3.scale: read great explanation and look at few examples.
I would like to look at two dimensional data in a time-series - the first idea I had was to use a scatter plot, where you can easily explore timepoint-to-timepoint. Is there a function I could use for this? I looked at scatter3 but it can only plot perfectly-cubic data, not as below:
e.g.
data=rand(5,5,3);
scatter3(data(1,:,:),data(:,1,:),data(:,:,1)) %throws an error
thanks
edit: Originally I had something like >this< in mind
scatter3 seems to be for 3D plots, but you say your data is 2D.
For a simple time-series graph you could presumably even just use plot:
figure
nPoints = 25;
dataX = 1:nPoints;
dataY = rand(1,nPoints);
plot(dataX,dataY, 'o-')
However, the example you give in your link looks like something else, so it seems like scatter (rather than scatter3) might be what you're after. Maybe something like this?
figure
nPoints = 25;
dataX = 1:nPoints;
dataY = rand(1,nPoints);
dataArea = rand(1,nPoints)*100;
dataColours = rand(nPoints,3);
scatter(dataX,dataY,dataArea,dataColours)
EDIT:
I think I understand better what you mean, sorry I didn't see the buttons at the bottom of the link, but correct me if I'm wrong. So you have a set of XY coordinates for multiple objects at different points in time, and ideally you want to plot how the XY coordinates of each object (in 2 dimensions) change over time (in 3 dimensions). Your initial approach in using scatter3 was to try and make a simple 3d graph, but maybe ideally you want a 2d graph that can be either animated or interactive, to change the time point displayed at any given time?
Going back to your original question, I think the issue with your attempt to use scatter3 (or plot3 might be useful too) is I'm not sure what your dummy data would represent. You created data as a 5x5x3 matrix, and I assume that might represent 25 data points, at 3 different time intervals? However, which data would represent the X and which the Y coordinates? It would work with something like the following, where each variable represents the X/Y/Z coordinates of 6 objects (columns) at 5 different time points (rows)
myX = rand(5,6,1);
myY = rand(5,6,1);
% I'm making each time point increase linearly.
myZ = repmat((1:size(myX,1))', 1, size(myX,2));
plot3(myX, myY, myZ, 'o-')
grid on
% Note I find the default dimensions it treats as X, Y and Z unintuitive (e.g. the Z dimension is the vertical dimension), but one could swap the input arguments around to overcome this.
However, especially if you have a lot of points, I'm not sure how clear a graph like this will be, especially compared to the example in your link.
Instead it seems like you ideally want only the XY coordinates of all objects to be plotted for only one time point at once, and a way to cycle through each time point sequentially. This seems trickier, and maybe someone else will be able to answer better than I have. A couple more questions though that might be useful:
How much do you care about the smoothness of the transition. In the example link the circles move smoothly from one position to another, rather than just jumping/teleporting between points.
Ideally do you want a function that would produce an 'animation', cycling through all the time points from begining to end, or a way of manually specifying/changing which time point is being displayed. If the former, maybe this function would be useful (though I've tried it myself yet) https://uk.mathworks.com/matlabcentral/fileexchange/42305-multicomet
I have 8 plots which I want to implement in my Matlab code. These plots originate from several research papers, hence, I need to digitize them first in order to be able to use them.
An example of a plot is shown below:
This is basically a surface plot with three different variables. I know how to digitize a regular plot with just X and Y coordinates. However, how would one digitize a graph like this? I am quite unsure, hence, the question.
Also, If I would be able to obtain the data from this plot. How would you be able to utilize it in your code? Maybe with some interpolation and extrapolation between the given data points?
Any tips regarding this topic are welcome.
Thanks in advance
Here is what I would suggest:
Read the image in Matlab using imread.
Manually find the pixel position of the left bottom corner and the upper right corner
Using these pixels values and the real numerical value, it is simple to determine the x and y value of every pixel. I suggest you use meshgrid.
Knowing that the curves are in black, then remove every non-black pixel from the image, which leaves you only with the curves and the numbers.
Then use the function bwareaopen to remove the small objects (the numbers). Don't forget to invert the image to remove the black instead of the white.
Finally, by using point #3 and the result of point #6, you can manually extract the data of the graph. It won't be easy, but it will be feasible.
You will need the data for the three variables in order to create a plot in Matlab, which you can get either from the previous research or by estimating and interpolating values from the plot. Once you get the data though, there are two functions that you can use to make surface plots, surface and surf, surf is pretty much the same as surface but includes shading.
For interpolation and extrapolation it sounds like you might want to check out 2D interpolation, interp2. The interp2 function can also do extrapolation as well.
You should read the documentation for these functions and then post back with specific problems if you have any.
Good day.
I got a scatter plotted in MatLab. I want to plot a trendline of the data on the plot as well. But instead of a normal quadratic curve fitting, I want to constrain the trendline with slope=0 when x=0. How could I achieve that?
And out of curiosity, how to constrain a trendline with must pass through specific point? Just like setting intercept in excel?
And can a trendline have multiple constrain like that I described above?
Thank you.
You want to fit a quadratic, a*x^2+b*x+c to your data, but you want the derivative to be zero somewhere. That is an extra constraint that will relate the variables. The derivative is 2*a*x+b so for it to be 0 at x=0, you need b=0. So you are now trying to fit a*x^2+c to your data. This is not too difficult,
A=[x(:).^2 ones(size(x(:)))];
coeffs=A\y(:);
fittedY=#(x) coeffs(1)*x.^2+coeffs(2)
And fittedY(x) gives the value of the fitted curve at x.
If you want your fit to have a certain value, rather than a certain derivative somewhere, you do a similar thing. Say you want the fit to equal 1 at x=1. Then a+b+c=1, so set c=1-b-a and the function you fit will be a*x^2+b*x+1-b-a.
You can use up to three such constraints, however using 3 constraints will (in general) uniquely determine a quadratic function, so there will be no parameters left to fit with.
So basically, the graph labeled "Thermal Wind" has an extreme value that compresses the y-values for all the other plots, making it much harder to see any of the individual variations in the other plots. Is there a way to neatly cut off this extreme value? I could just rescale the y limit to a maximum of 40, but then this looks ugly.
As for the alternative I've tried - it's here:
I would recommend trying to plot it on a log scale. The function you'll want to consider using is semilogx, though for completeness I recommend also reading the help file on loglog.
Alternately, you could use subplot to generate multiple plots, one of which is zoomed into a region of interest.
Are the outlier points errors in the data, or do they represent extreme cases?
If they are not valid data, just manually exclude them from the data, plot the graph, and include a text clarification when describing the graph. If they are valid data, then trimming them would misrepresent the data, which isn't a good thing.
Graphs of data aren't art: their main goal isn't to be pretty; it's to provide a useful visualization of data. There are some minimum requirements on appearance, however: the axes have to be labeled, the units have to be meaningful, the different curves have to be visually distinct, etc. As long as your graph has these things, you shouldn't expect to lose marks for presentation.
There are two approaches that I use:
One approach would be transform the data so it will fill the plot nicely. Make the transform so that it wouldn't touch the range - say -10 to +10. In your case you could choose it so that 100 transforms to +15 and -100 to -15.
For clarity you need to then also set and label the y ticks appropriately. And for nice style make sure the line changes slope when it goes over the border.
I plot the data as is. But set the axis limits say from -10 to +10. Where points lay outside I place upwards and downwards triangles along the border to mark in which direction the "outliers" would be. Obviously this is only good when there aren't too many.