Showing posts with label figures. Show all posts
Showing posts with label figures. Show all posts

Monday, June 23, 2014

Annotating subscript in R plots

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.

Wednesday, July 17, 2013

plotting 3D vector field in MATLAB in many different ways

Recently I read post from Dr. Doug Hull's blog:

http://blogs.mathworks.com/videos/2009/10/23/basics-volume-visualization-19-defining-scalar-and-vector-fields/

I liked this video tutorial so much and I really felt that should finish the 'homework' assigned at the very end. So I spent sometime on it and here are my code and figures.

clear;close all;clc;
load wind
speed=sqrt(u.*u+v.*v+w.*w);
%%
figure(1)
scatter3(x(:),y(:),z(:),[],speed(:))
%%
figure(2)
slice(x,y,z,speed,[],[],[5 10 15])
zlim([0 20])
%%
figure(3)
[xs, ys]=meshgrid(60:140, 20:60);
zs=20*ys./xs;
slice(x,y,z,speed,xs,ys,zs)
%%
figure(4)
contourslice(x,y,z,speed,[],[],[5 10 15],20)
zlim([0 20])
view(3)

%%
figure(5)
fv1=isosurface(x,y,z,speed, 10);
fv2=isosurface(x,y,z,speed, 20);
fv3=isosurface(x,y,z,speed, 30);
h1=patch(fv1);
h=patch(fv2);
h3=patch(fv3);
set(h1,'FaceColor',[1, 0.6, 0])
set(h1,'EdgeColor','none')

set(h,'FaceColor',[0, 0.5, 0.5])
set(h,'EdgeColor','none')

set(h3,'FaceColor',[1, 0.4, 1])
set(h3,'EdgeColor','none')
camlight;
lighting gouraud
view(3)

%% 
figure(6)
quiver3(x,y,z,u,v,w);

%%
figure(7)
[cx,cy,cz]=meshgrid([70 80 90 100 110 120], [20 30 40 50 60],[0 5 10 15]);
coneplot(x,y,z,u.*100,v.*100,w.*100,cx,cy,cz,speed);
% set(h, 'edgecolor','none')
shading interp;
view(3)

%%
figure(8)
streamline(x,y,z,u,v,w,80,40,10)
hold on
plot3(80,40,10, 'bo')
view(3)

%%
figure(9)
[sx,sy,sz]=meshgrid(100,[20 30 40], [5 10]);
streamline(x,y,z,u,v,w,sx,sy,sz)
hold on
plot3(sx(:),sy(:),sz(:),'bo')
view(3)

%%
figure(10)
streamslice(x,y,z,u,v,w,[],[],1)
view(3)

%%
figure(11)
streamtube(x,y,z,u,v,w,sx,sy,sz)
shading interp;
view(3)
%%
figure(12)
h=streamribbon(x,y,z,u,v,w,sx,sy,sz);
shading interp;
view(3)


Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

Figure 7

Figure 8

Figure 9

Figure 10

Figure 11

Figure 12



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)  



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:

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.

Friday, July 1, 2011

Cell array, self-defined function, and save fig

I learned a lot of important things yesterday, after spend 10 hours in front of computer playing with MatLab. Alright, here's the code I came up with.


%Created on 6/30/2011
clear all
clc
sitenumber='01';


SampleLocation=[];
AER=[];
Err=[];




%% Importing data from intermediate file
filename='whatever it is.xlsx';
D1=xlsread(filename, 'A14:C25');
D2=xlsread(filename, 'I14:K25');
D3=xlsread(filename, 'Q14:S25');
D4=xlsread(filename, 'Y14:AA25');
D5=xlsread(filename, 'AG14:AI25');
D6=xlsread(filename, 'AO14:AQ25');
D7=xlsread(filename, 'AW14:AY25');
D8=xlsread(filename, 'BE14:BG25');
D9=xlsread(filename, 'BM14:BO25');
D10=xlsread(filename, 'BU14:BW25');
D11=xlsread(filename, 'CA14:CD25');
D12=xlsread(filename, 'CJ14:CL25');
D13=xlsread(filename, 'CR14:CT25');
D14=xlsread(filename, 'CZ14:DB25');
D15=xlsread(filename, 'DH14:DJ25');
D16=xlsread(filename, 'DP14:DR25');
D17=xlsread(filename, 'DX14:DZ25');
D18=xlsread(filename, 'EF14:EH25');
DCell={D1,D2,D3,D4,D5,D6,D7,D8,D9,D10,...
    D11,D12,D13,D14,D15,D16,D17,D18}; % Put all the arrays into one big cell array so that each time I can take one cell out and use it as the function input. 


% Use each array as function input % This is a self-defined function
for k=1:18
    [AERate Error]=getDecayrate(DCell{k}); %If use DCell (k), the function won't work.
    
    SampleLocation(1,k)=k;
    AER(1,k)=AERate;
    Err(1,k)=Error;
        
    newfilename=strcat('Site_', sitenumber, '_SampleLocation_', num2str(k),'.fig');
    saveas(gcf,newfilename) % This saveas function works pretty good. The .fig file can be edited later in MatLab.
end


 Result=[SampleLocation', AER', Err'];


%The following function calculates the first-order decay rate of the tracer gas, and returns two parameters. 

function [AER Err] = getDecayrate( location)
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here


%AER=Data-1;
TimeS=zeros(1, length(location))';
LNC1=zeros(1, length(location))';
LNC2=zeros(1, length(location))';
for i=2 : length(location)
        TimeS(i)=(location(i,1)-location(1,1))*1440/60;
end


for j=2 : length(location)
    LNC1(j)=log(location(j,2)/location(1,2));
    LNC2(j)=log(location(j,3)/location(1,3));
end


slope1=sum(TimeS.*LNC1)/sum(TimeS.^2);
slope2=sum(TimeS.*LNC2)/sum(TimeS.^2);
AER=abs((slope1+slope2)/2);
Err=abs(AER-abs(slope1));
TimeModel=0:0.01:max(TimeS);
LNC1Model=TimeModel.*slope1;
LNC2Model=TimeModel.*slope2;
plot(TimeS, LNC1, 'xr',TimeS, LNC2, 'sb', TimeModel, LNC1Model,'r', TimeModel, LNC2Model, 'b', 'MarkerSize',10, 'LineWidth', 2)
title ('Location')
xlabel('Time (hours)')
ylabel('Ln(C/C0)')
end


my-alpine and docker-compose.yml

 ``` version: '1' services:     man:       build: .       image: my-alpine:latest   ```  Dockerfile: ``` FROM alpine:latest ENV PYTH...