Beinsearch
5/26/2017 - 2:20 PM

## R可视化.r

``````#PIL
from PIL import Image,ImageDraw
img=Image.new('RGB',(400,400),(255,255,255))  #白色
draw=ImageDraw.Draw(img)
#画线
draw.line((pos[a],pos[b]),fill=(255,0,0)) #红色
#写文字
draw.text((pos[a],pos[b]),people,(0,0,0)) #黑色
img.show()

#matplotlib
import math
import matplotlib.pyplot as plt
plt.figure(1)
plt.title("Figure1")
plt.xlabel("x", size=14)
plt.ylabel("y", size=14)
x = np.array([t for t in range(0, 100)])
y = [math.sin(t) for t in x]
#fitness = np.array(fitness)
plt.plot(x, y, color='b', linewidth=3)
for i in range(len(x)):
plt.text(x[i], y[i], i, color='red',fontsize=10)
plt.show()

#直方图
import matplotlib.pyplot as plt
import seaborn as sns
color = sns.color_palette()

nt = orders['order_dow'].value_counts()
plt.figure(figsize=(12,6))
sns.barplot(cnt.index, cnt.values, alpha=0.8, color=color[3])   #alpha表示颜色的深浅
plt.xlabel('Day of Week', fontsize=12)
plt.ylabel('Order Num', fontsize=12)
plt.show()``````
``````##矩形式树状结构图
##https://www.kaggle.com/philippsp/first-exploratory-analysis
library(treemap)

tmp <- products %>% group_by(department_id, aisle_id) %>% summarize(n=n())
tmp <- tmp %>% left_join(departments,by="department_id")
tmp <- tmp %>% left_join(aisles,by="aisle_id")

tmp2<-order_products %>%
group_by(product_id) %>%
summarize(count=n()) %>%
left_join(products,by="product_id") %>%
ungroup() %>%
group_by(department_id,aisle_id) %>%
summarize(sumcount = sum(count)) %>%
left_join(tmp, by = c("department_id", "aisle_id")) %>%
mutate(onesize = 1)

treemap(tmp2,index=c("department","aisle"),vSize="onesize",vColor="department",palette="Set3",title="",sortID="-sumcount", border.col="#FFFFFF",type="categorical", fontsize.legend = 0,bg.labels = "#FFFFFF")
##效果图
https://www.kaggle.io/svf/1179219/e3e940f30524d3d0b7b42e82fa22dba7/__results___files/figure-html/unnamed-chunk-24-1.png``````