#!/usr/bin/env python
# coding: utf-8
# [Sebastian Raschka](http://www.sebastianraschka.com)
#
# [back](https://github.com/rasbt/matplotlib-gallery) to the `matplotlib-gallery` at [https://github.com/rasbt/matplotlib-gallery](https://github.com/rasbt/matplotlib-gallery)
# In[1]:
get_ipython().run_line_magic('load_ext', 'watermark')
# In[2]:
get_ipython().run_line_magic('watermark', '-u -v -d -p matplotlib,numpy')
# [More info](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/ipython_magic/watermark.ipynb) about the `%watermark` extension
# In[3]:
get_ipython().run_line_magic('matplotlib', 'inline')
# # Special plots in matplotlib
# # Sections
# - [Basic pie chart](#Basic-pie-chart)
# - [Basic triangulation](#Basic-triangulation)
# - [xkcd-style plots](#xkcd-style-plots)
#
#
# # Basic pie chart
# [[back to top](#Sections)]
# In[5]:
from matplotlib import pyplot as plt
import numpy as np
plt.pie(
(10,5),
labels=('spam','ham'),
shadow=True,
colors=('yellowgreen', 'lightskyblue'),
explode=(0,0.15), # space between slices
startangle=90, # rotate conter-clockwise by 90 degrees
autopct='%1.1f%%',# display fraction as percentage
)
plt.legend(fancybox=True)
plt.axis('equal') # plot pyplot as circle
plt.tight_layout()
plt.show()
#
#
# # Basic triangulation
# [[back to top](#Sections)]
# In[5]:
from matplotlib import pyplot as plt
import matplotlib.tri as tri
import numpy as np
rand_data = np.random.randn(50, 2)
triangulation = tri.Triangulation(rand_data[:,0], rand_data[:,1])
plt.triplot(triangulation)
plt.show()
#
#
# # xkcd-style plots
# [[back to top](#Sections)]
# In[7]:
import matplotlib.pyplot as plt
x = [1, 2, 3]
y_1 = [50, 60, 70]
y_2 = [20, 30, 40]
with plt.xkcd():
plt.plot(x, y_1, marker='x')
plt.plot(x, y_2, marker='^')
plt.xlim([0, len(x)+1])
plt.ylim([0, max(y_1+y_2) + 10])
plt.xlabel('x-axis label')
plt.ylabel('y-axis label')
plt.title('Simple line plot')
plt.legend(['sample 1', 'sample2'], loc='upper left')
plt.show()
# In[8]:
import numpy as np
import random
from matplotlib import pyplot as plt
data = np.random.normal(0, 20, 1000)
bins = np.arange(-100, 100, 5) # fixed bin size
with plt.xkcd():
plt.xlim([min(data)-5, max(data)+5])
plt.hist(data, bins=bins, alpha=0.5)
plt.title('Random Gaussian data (fixed bin size)')
plt.xlabel('variable X (bin size = 5)')
plt.ylabel('count')
plt.show()
# In[9]:
from matplotlib import pyplot as plt
import numpy as np
with plt.xkcd():
X = np.random.random_integers(1,5,5) # 5 random integers within 1-5
cols = ['b', 'g', 'r', 'y', 'm']
plt.pie(X, colors=cols)
plt.legend(X)
plt.show()
#
#