import json
import matplotlib
s = json.load( open("styles/qutip_matplotlibrc.json") ) #edit path to json file
matplotlib.rcParams.update(s)
%pylab inline
from IPython.display import Image, HTML
HTML('''
The raw code for this IPython notebook is by default hidden for easier reading.
To toggle on/off the raw code, click here.''')
Image(filename='images/mpl.png',width=700,embed=True)
from pylab import *
from numpy import *
x=linspace(-pi,pi)
y=sin(x)
plot(x,y)
show()
x=linspace(-pi,pi)
y=sin(x)
plot(x,y,'r--') #make line red 'r' and dashed '--'
xlabel('x')
ylabel('y')
title('sin(x)')
show()
x=linspace(-pi,pi)
y=sin(x)
plot(x,y,'--',color='0.75') # Here a string from 0->1 specifies a gray value.
show()
x=linspace(-pi,pi)
y=sin(x)
plot(x,y,'-',color='#FD8808') # We can also use hex colors if we want.
show()
x=linspace(-pi,pi)
y=sin(x)
figure(figsize=(12,3)) #This controls the size of the figure
subplot(2,3,1) #This is the first plot in a 2x3 grid of plots
plot(x,y)
subplot(2,3,2)#this is the second plot
plot(x,y,linestyle='--') # Demo using 'linestyle' keyword arguement
subplot(2,3,3)
plot(x,y,'.')
subplot(2,3,4)
plot(x,y,'-.')
subplot(2,3,5)
plot(x,y,'.-')
subplot(2,3,6)
plot(x,y,ls=':') # Demo using 'ls' keyword arguement.
show()
x=linspace(0,10)
y=sqrt(x)
figure(figsize=(12,3))
subplot(1,3,1)
plot(x,y)
subplot(1,3,2)
plot(x,y,linewidth=2)
subplot(1,3,3)
plot(x,y,lw=7.75)
show()
x=linspace(0,10)
s=sin(x)
c=cos(x)
sx=x*sin(x)
figure(figsize=(12,3))
subplot(1,2,1)
plot(x,s,'b') #call three different plot functions
plot(x,c,'r')
plot(x,sx,'g')
subplot(1,2,2)
plot(x,s,'b',x,c,'r',x,sx,'g') #combine multiple lines in one call to plot
show()
x=linspace(-pi,pi,100)
figure(figsize=(12,3))
subplot(1,3,1)
plot(x,sin(x),lw=2)
subplot(1,3,2)
plot(x,sin(x),lw=2,color='#740007')
xlim([-pi,pi]) #change bounds on x-axis to [-pi,pi]
subplot(1,3,3)
plot(x,sin(x),'^',ms=8,color='0.8')
xlim([-1,1]) #change bounds on x-axis to [-1,1]
ylim([-0.75,0.75]) #change bounds on y-axis to [-0.75,0.75]
show()
x=linspace(-pi,pi,100)
figure(figsize=(12,3))
subplot(1,3,1)
plot(x,sin(x),lw=2)
subplot(1,3,2)
plot(x,sin(x),lw=2,color='#740007')
xlim([-pi,pi])
subplot(1,3,3)
plot(x,sin(x),'^',ms=8,color='0.8')
xlim([-1,1])
ylim([-0.75,0.75])
savefig('axes_example.png') #Save the figure in PNG format in same directory as script
from scipy.special import airy #Airy functions are in the SciPy special module
x = linspace(-1,1)
Ai,Aip,Bi,Bip = airy(x)
plot(x,Ai,'b*',x,Aip,'ro',x,Bi,'gs',x,Bip,'k+')
show()
x = np.linspace(-1, 1., 100)
figure(figsize=(6,6))
subplot(2,2,1)
y=x+0.25*randn(len(x))
scatter(x,y,color='r') #plot collection of (x,y) points
title('A scatter Plot')
subplot(2,2,2)
n = array([0,1,2,3,4,5])
bar(n, n**2, align="center", width=1) #aligns the bars over the x-numbers, and width=dx
title('A bar Plot')
subplot(2,2,3)
fill_between(x, x**2, x**3, color="green") #fill between x**2 & x**3 with green
title('A fill_between Plot')
subplot(2,2,4)
title('A hist Plot')
r=random.randn(50) # generating some random numbers
hist(r,color='y') #create a histogram of the random number values
show()
from IPython.core.display import HTML
def css_styling():
styles = open("styles/style.css", "r").read()
return HTML(styles)
css_styling()