Last active
October 1, 2018 04:41
-
-
Save sabopy/1a824226718f72416c925f543efeab3f to your computer and use it in GitHub Desktop.
画像つき円グラフ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# AWS cloud9 | |
import matplotlib | |
matplotlib.use("Agg") | |
import matplotlib.pyplot as plt | |
import pandas as pd | |
from matplotlib.offsetbox import OffsetImage, AnnotationBbox | |
plt.rcParams["font.size"] = 16 | |
data = pd.read_table('data/Dino_2018_0909_1002.tsv', parse_dates=[0]) | |
sabo_num = data['Dead'].str.contains('sabo').sum() | |
bird_num = data['Dead'].str.contains('bird').sum() | |
all_num = sabo_num + bird_num | |
img_c = plt.imread('image/plant_cactus.png') | |
img_b = plt.imread('image/Pteranodon.png') | |
fig = plt.figure(figsize=(6, 4)) | |
ax = fig.add_subplot(111) | |
data=[sabo_num,bird_num] | |
label=['サボテン','鳥'] | |
plt.axis('equal') | |
ax.pie(data, labels=label,autopct="%.1f%%", labeldistance=0.4) | |
imagebox = OffsetImage(img_c, zoom=0.3) | |
imagebox.image.axes = ax | |
im_sabo = AnnotationBbox(imagebox, (-0.7, 0), | |
xybox=(-1.5, 0), | |
xycoords='data', | |
boxcoords="data", | |
pad=0.3, | |
arrowprops=dict(arrowstyle="simple, head_width = 0.4, head_length = 0.4", | |
lw=0.1,fc="0", ec="0")) | |
ax.add_artist(im_sabo) | |
imagebox_2 = OffsetImage(img_b, zoom=0.2) | |
imagebox_2.image.axes = ax | |
im_bird = AnnotationBbox(imagebox_2, (0.55,-0.6), | |
xybox=(1.4, -0.9), | |
xycoords='data', | |
boxcoords="data", | |
pad=0.3, | |
arrowprops=dict(arrowstyle="simple, head_width = 0.4, head_length = 0.4", | |
lw=0.1,fc="0", ec="0")) | |
ax.add_artist(im_bird) | |
ax.text(-0.15,-1.2,all_num,ha='center') | |
ax.text(-0.05,-1.2,"times") | |
fig.savefig("piechart_cause_of_death.png", dpi=200,transparent = False, bbox_inches = 'tight') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment