In [47]:
import numpy as np 
import matplotlib.pyplot as plt
%matplotlib inline
xPoints = np.linspace(0, 2*np.pi, 100)
data1 = np.sin(xPoints)
data2 = np.cos(xPoints)
# Set color with key word 'color' or the shortcat 'c'
# gray scale 0.0 = black  , 1.0 = while
plt.plot(data1,  color='0.2')
plt.plot(data2,  color='0.8')
plt.plot(data1 + data2, color='0.0')
Out[47]:
[<matplotlib.lines.Line2D at 0x113333ac8>]
In [37]:
import numpy as np 
import matplotlib.pyplot as plt
%matplotlib inline
xPoints = np.linspace(0, 2*np.pi, 100)
data1 = np.sin(xPoints)
data2 = np.cos(xPoints)
## Colors
# b = blue 
# g = green 
# r = red
# c Cyan
# m Magenta
# y Yellow
# k Black 
# w white
plt.plot(data1,  color='c', linestyle='dashed')
plt.plot(data2, color='g', marker='.' )
plt.plot(data2+0.2, color='m', marker='o', markevery=4 )
# we set a line width with the keyword 'linewidth'
plt.plot(data1 + data2, color='r', linewidth=3)
Out[37]:
[<matplotlib.lines.Line2D at 0x1110dbd30>]
In [31]:
import numpy as np 
import matplotlib.pyplot as plt
%matplotlib inline
data = np.random.standard_normal((100,2))
# Control the edge color of a dot with keyword 'edgecolor'
x = data[:,0]
y =  data[:,1]
plt.scatter(x,y, color='w', edgecolor='k')
plt.scatter(y-2,x-2, color='w', edgecolor='r', s=100)
Out[31]:
<matplotlib.collections.PathCollection at 0x1109e4a20>
In [4]:
# make a boxplot appear totally black
import numpy as np 
import matplotlib.pyplot as plt
%matplotlib inline

data = np.random.randn(200)

box = plt.boxplot(data)

for _, line_list in box.items():
    for line in line_list:
        line.set_color('k')

plt.show()
In [15]:
# Plotting stacked bars

import matplotlib.pyplot as plt

# notebook command to show the plot in the browser
%matplotlib inline 

d1 = [1,3,5,7]
d2 = [4,5,7,8]

x = range(len(d1))

plt.bar(x, d1, color='w' , hatch='x')           # the function bar is used to plot bar charts
plt.bar(x, d2, color='0.8' , bottom=d1, hatch='/')# the optional parammeter bottom specifies the starting point for bars

plt.show()
In [36]:
# Control the markers
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-5,5, 500)
y = np.sinc(x)

plt.plot(x,y,
         linewidth = 4,
         color = 'g', 
         markersize = 15, 
         markeredgewidth = 1.5, 
         markerfacecolor = '0.75',
         markeredgecolor = 'k',
         marker = 'o',
         markevery = 16)
plt.show()
In [9]:
# Tick spacing
import numpy as np 
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

%matplotlib inline
xPoints = np.linspace(0, 2*np.pi, 100)
data1 = np.sin(xPoints)

ax = plt.axes()      # get instance of the axes object
ax.xaxis.set_major_locator(ticker.MultipleLocator(20)) 
ax.xaxis.set_minor_locator(ticker.MultipleLocator(5))
plt.plot(data1,  color='0.2')

plt.grid(True, 
         which='both') # which can accept major, minor, or both
plt.show()
In [20]:
# Tick labelling (First approach)

import matplotlib.pyplot as plt
%matplotlib inline 

d1 = [1,3,5,7]
x = range(len(d1))

labels = ['first', 'second', 'third', 'fourth' ]
locations=[0,1,2,3]

ax = plt.axes()
ax.xaxis.set_major_locator(ticker.FixedLocator(locations))
ax.xaxis.set_major_formatter(ticker.FixedFormatter(labels))

plt.bar(x, d1, color='0.7', align='center')   # algin the locations of the labels (major ticks)       

plt.show()
In [21]:
# Tick labelling (Second approach)

import matplotlib.pyplot as plt
%matplotlib inline 

d1 = [1,3,5,7]
x = range(len(d1))

labels = ['first', 'second', 'third', 'fourth' ]
locations=[0,1,2,3]

plt.bar(x, d1, color='0.7', align='center')   # algin the locations of the labels (major ticks)       
plt.xticks(locations, labels)   # using xticks to set the labels
plt.show()
In [49]:
# labelling with a function (delegation)
import numpy as np 
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

def make_label(value, pos):
    return '{0:.1f}%'.format(100. * value)

ax= plt.axes()
ax.xaxis.set_major_formatter(ticker.FuncFormatter(make_label))
X = np.linspace(0,1, 256)

plt.plot(X,np.exp(-10 * X), c = 'k')
plt.plot(X,np.exp(-5 * X), c = 'k', ls='--')

plt.show()