UP | HOME

Exercise 21 solutions

Table of Contents


Python

e21.py

# ipython --pylab

# part 1
x = [1,2,3,4,5]
y1 = array([1,2,3,4,4])
y2 = array([1,5,6,8,10])
y3 = array([5,4,2,2,1])
m = matrix((y1,y2,y3)).T
plot(x, m, '-o', linewidth=3, markersize=10)
xlabel("X")
ylabel("Y")

# part 2
legend(("Y1","Y2","Y3"), loc="upper left")

MATLAB / Octave

e21.m

# part 1
x = [1,2,3,4,5]
y1 = [1,2,3,4,4]
y2 = [1,5,6,8,10]
y3 = [5,4,2,2,1]
plot(x,[y1;y2;y3]','.-','markersize',35, 'linewidth',3)
xlabel('X')
ylabel('Y')

# part 2
legend('Y1','Y2','Y3', 'location', 'northwest')

R

e21.R

# part 1
x <- c(1,2,3,4,5)
y1 <- c(1,2,3,4,4)
y2 <- c(1,5,6,8,10)
y3 <- c(5,4,2,2,1)
d = matrix(c(y1,y2,y3), nrow=5, ncol=3)
matplot(x, d, type="b", col=c("blue","green","red"), pch=19, lty=1, lwd=3, ylab="Y", xlab="X")

# part 2
legend("topleft", legend=c("Y1","Y2","Y3"), col=c("blue","green","red"), pch=19, lwd=3)

Paul Gribble | fall 2014
This work is licensed under a Creative Commons Attribution 4.0 International License
Creative Commons License