In [1]:
import sys
print(sys.version)


2.7.13 |Anaconda 4.3.1 (x86_64)| (default, Dec 20 2016, 23:05:08) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]

In [2]:
import matplotlib.pyplot as plt
%matplotlib inline 
# plotting in notebook
plt.rcParams["figure.figsize"] = (10,10) # fig size
import seaborn as sns
import webcolors

#%config InlineBackend.figure_format = 'pdf' # pdf for use in latex

from matplotlib.font_manager import FontProperties
import matplotlib.font_manager as font_manager

Using custom fonts

Relevant fontName.ttf font need to be downloaded


In [3]:
# help(font_manager)

path = '../fonts/segoeuib.ttf'
prop = font_manager.FontProperties(fname=path)
print prop.get_name()
print prop.get_family()

font0 = FontProperties()
font1 = font0.copy()
font1.set_family(prop.get_name())


Segoe UI
[u'sans-serif']

Donut plot in matplotlib


In [5]:
# Data to plot
labels = ['Python', 'R','MATLAB', 'C', 'C++']
sizes = [36, 19, 28, 8, 9]
colors = ['#2196F3','#FF5722', '#FFC107', '#CDDC39', '#4CAF50']
# explode = (0.1, 0, 0, 0)  # explode 1st slice
explode = (0, 0, 0, 0, 0)  # explode 1st slice

plt.figure(figsize=(8,8))
patches, texts = plt.pie(sizes, explode=explode, labels=labels, labeldistance=0.65, colors=colors,
        autopct=None, shadow=False, startangle=22)

for item in texts:
    item.set_fontproperties(font1)
    item.set_fontsize(30)
    item.set_horizontalalignment('center')
    item.set_weight('bold')
    #item.set_family(prop.get_family())


#draw a circle at the center of pie to make it look like a donut
centre_circle = plt.Circle((0,0),0.4,color='#E7E7E7',linewidth=1.25)
fig = plt.gcf()
fig.gca().add_artist(centre_circle)

plt.axis('equal')
plt.tight_layout()
# plt.savefig('donut.pdf',transparent=True)
plt.show()


You are welcome!