I need to annotate one of my figure like this:
(b) PM2.5
And this is a way to do it in R with ggplot2 package:
b <- b="" font="">->
annotate("text", x=-3.5, y=0.12, label=deparse(b),parse=TRUE)
Not sure about the details behind all the parameters though. Thanks to BondedDust for answering this question.
MATLAB applications, tutorials, examples, tricks, resources,...and a little bit of everything I learned ...
Showing posts with label plot. Show all posts
Showing posts with label plot. Show all posts
Monday, June 23, 2014
Thursday, September 19, 2013
windrose plot by sigmaplot and matlab
I used two methods to plot wind direction and speed data: Sigmaplot and Matlab.
To correctly show the wind is blowing from the degree, say 10 degree, I need to check the 'clock wise' option. Otherwise the direction will be wrong.
When I used the wind_rose.m, which is downloaded from this link:
http://www.mathworks.com/matlabcentral/fileexchange/17748-windrose
the correct way is to use D-180, and set the 'dtype' to 'meteo'.
This way the two plots made by two different methods will be consistent and correct.
To correctly show the wind is blowing from the degree, say 10 degree, I need to check the 'clock wise' option. Otherwise the direction will be wrong.
When I used the wind_rose.m, which is downloaded from this link:
http://www.mathworks.com/matlabcentral/fileexchange/17748-windrose
the correct way is to use D-180, and set the 'dtype' to 'meteo'.
This way the two plots made by two different methods will be consistent and correct.
Wednesday, August 14, 2013
Matlab: plot 3D object defined by function g=f(x,y,z)
Usually a 3D object can be described by function of x,y, and z. For example, a 3D sphere centered at (0,0,0) can be described as:
x^2+y^2+z^2=r^2
where the r s the radius of the sphere.
How to plot this object in matlab? Here's my solution:
close all;
clc;
clear;
[x, y,z]=meshgrid(-3:0.1:3, -3:0.1:3,-3:0.1:3);
v1=x.^2+y.^2+z.^2; % create the 1st object
r1=2;% set radius
p1=patch(isosurface(x,y,z,v1,r1));
set(p1, 'FaceColor','r')
hold on
v2=(x-1).^2+(y-1).^2+(z-1).^2;% create the 2nd object
r2=3;
p2=patch(isosurface(x,y,z,v2,r2));
set(p2,'FaceColor','b')
view(3)% set to 3D view
x^2+y^2+z^2=r^2
where the r s the radius of the sphere.
How to plot this object in matlab? Here's my solution:
close all;
clc;
clear;
[x, y,z]=meshgrid(-3:0.1:3, -3:0.1:3,-3:0.1:3);
v1=x.^2+y.^2+z.^2; % create the 1st object
r1=2;% set radius
p1=patch(isosurface(x,y,z,v1,r1));
set(p1, 'FaceColor','r')
hold on
v2=(x-1).^2+(y-1).^2+(z-1).^2;% create the 2nd object
r2=3;
p2=patch(isosurface(x,y,z,v2,r2));
set(p2,'FaceColor','b')
view(3)% set to 3D view
x^2+y^2+z^2=r^2
(x+2-y^2)^2+y^2+z^2=6
(x+2-y^2+z^3)^2+y^2+z^2=6
Tuesday, December 13, 2011
Set marker edge width in Matlab figures
A couple of days ago, I plotted about twenty figures and was trying to set the markers with thicker edge. This would be very easy if it was in Excel: just change the 'Marker Line Style' in the 'Format data series' tab. However, it was kind difficult to do in Matlab. At least I didn't get a good solution from the google results on that day.
Today I happened to find the solution when I was playing with Matalb just for fun. The fact is that the 'Marker Edge Width' is actually defined by the 'LineWidth', even when the plot does not use a line to connect the markers..
t=[1:5];
plot(t,sin(t), 's', 'Markersize', 20,'LineWidth', 5)
Today I happened to find the solution when I was playing with Matalb just for fun. The fact is that the 'Marker Edge Width' is actually defined by the 'LineWidth', even when the plot does not use a line to connect the markers..
t=[1:5];
plot(t,sin(t), 's', 'Markersize', 20,'LineWidth', 5)
Sunday, November 13, 2011
Excel slope function vs linest function
To get the slope of a pair of x and y, usually I first plot the curve and then add the trend line.
Actually there are two functions in Excel to help me do this. The first one is the 'SLOPE' function. However, it only gives what is shown by the red trend line (slope=0.25). The second one is 'LINEST' function, which is more flexible. By setting the third parameters in the function to 'False', it automatically set the intercept to zero (slope=0.36).
'LINEST=(y series, x series, False)'
Friday, October 14, 2011
Best way to make a stairs graph
Today I got two sets of data and wanted to present them in one stairs graph. So I tried Excel, MATLAB, and Sigmaplot. The conclusion is that Sigmaplot is the best software to draw something like this figure:
The plotyy function in matlab can be used to create figures with secondary Y axis, however, if you manually set the Xticklabel, the labels will be messed up, like this figure shows:
The plotyy function in matlab can be used to create figures with secondary Y axis, however, if you manually set the Xticklabel, the labels will be messed up, like this figure shows:
Thursday, October 6, 2011
Some useful statistic toolbox functions
I was working on some statistical problem today, with some real measured data on hand. The statistics I learned more than 10 years ago have all faded in my memory. So I have to use some books and the Matlab demos to help me recall those fundamental things in statistics. Here I got a set of measured data:
CN=[0, 53, 110, 144, 199, 199, 203, 188, 176, 171, 199, 184, 154, 129, 101, 41, 0]
CN=[0, 53, 110, 144, 199, 199, 203, 188, 176, 171, 199, 184, 154, 129, 101, 41, 0]
It looks like a bell shape curve , so I guessed a normal distribution. But how do I know if it is normally distributed, in a more scientific way? Later I found these two functions to be very useful.
normplot(CN)
lillietest(CN)
The normplot gives a figure as this:
If the scatters follow the line, as it is in the above figure, the data can be seen as approximately normally distributed. But why? I don't know. This is what the demo says.
The lillite test can give even more scientific answer to the question of whether the data is normally distributed or not. After running the lillietest(CN), I got
ans =
0
This result gives me a definite answer that yes, this set of data is normally distributed. And why? I don't know, again!
Monday, September 26, 2011
Plot multiple figures by one matlab code
plot (x1,y1)
figure (2)
plot (x2,y2)
figure (3)
plot (x3, y3)
This is how to create some new blank figures and plot on them.
Subscribe to:
Posts (Atom)
my-alpine and docker-compose.yml
``` version: '1' services: man: build: . image: my-alpine:latest ``` Dockerfile: ``` FROM alpine:latest ENV PYTH...
-
It took me a while to figure out how to insert a space in Mathtype equations. This is especially useful when you write an equation with mult...
-
In this post, I am trying to solve the problem given in the comments of one of the old post. Here's the problem, if I understand it co...
-
Recently I got a very long column of data and it contains lots of NaN. I found the finite function very useful to help me remove all the NaN...




