In [1]:
import sys
print(sys.version)
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
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())
labeldistance
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!