In [1]:
# Basic matplotlib import (with "magic" %matplotlib inline
# function for integration with matplotlib)
%matplotlib inline
from matplotlib import pyplot as plt
import numpy as np

Manipulate plot axes, titles, etc.


In [2]:
x = np.arange(-5,5.1,0.1)

plt.plot(x,x**2,"-")

# Set axis labels
plt.xlabel("x")
plt.ylabel("x^2")

# set title
plt.title("this is the title")

# set x and y ranges
plt.xlim((-6,6))
plt.ylim((-10,30))


plt.show()


Plot sundry things

Point types


In [3]:
point_types = [".",",","o","v","^","<",">","1","2","3","4","8",
               "s","p","P","*","h","H","+","x","X","D","d","|",
               "_"]
for i in range(len(point_types)):
    plt.plot([2*i,2*i+4],[2*i,2*i],point_types[i],color="black")

plt.show()


Line types


In [4]:
line_types = ["-","--",":"]
for i in range(len(line_types)):
    plt.plot(x,5*i+x**2,line_types[i])


Colors


In [5]:
# blue, green, red, cyan, magenta, yellow, black, white
colors = ["b","g","r","c","m","y","k","w"]

for i in range(len(colors)):
    plt.plot([2*i,2*i+4],[2*i,2*i],"o",color=colors[i])


show


In [6]:
# dashed line and points on top of each other
plt.plot(x,x**2,"--")
plt.plot([-4,-2,0,2,4],[-4,-2,0,2,4],"o",color="red")
plt.show()

# dashed line
plt.plot(x,x**2,"--")
plt.show()

# points
plt.plot([-4,-2,0,2,4],[-4,-2,0,2,4],"o",color="red")
plt.show()


Write out a pdf


In [ ]:
plt.plot(x,x**2)
plt.savefig("junk.pdf")