绘制散点图

1430-王同学

发表文章数:21

首页 » 数据科学库 » 正文

01绘制散点图

from matplotlib import pyplot as plt
from matplotlib import font_manager
y_3 = [11,17,16,11,12,11,12,6,6,7,8,9,12,15,14,17,18,21,16,17,20,14,15,15,15,19,21,22,22,22,23]
y_10 = [26,26,28,19,21,17,16,19,18,20,20,19,22,23,17,20,21,20,22,15,11,15,5,13,17,10,11,13,12,13,6]
x_3 = range(1,32)
x_10 = range(51,82)
plt.figure(figsize=(20,8),dpi=80)#图形大小
#使用scatter方法绘制散点图
plt.scatter(x_3,y_3,label="3 month")
plt.scatter(x_10,y_10,label="10 month")
_x = list(x_3)+list(x_10)
_xtick_labels = ["3m{}d".format(i) for i in x_3]
_xtick_labels += ["10m{}d".format(i) for i in x_10]
plt.xticks(_x[::3],_xtick_labels[::3],rotation=45) #调整x轴的刻度
#描述信息
plt.xlabel("time")
plt.ylabel("tempt")
plt.title("time-tempt")
#图例
plt.legend(loc = "upper left")
plt.show()
#绘制横着的条形图
from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname="C:/Windows/Fonts/msyh.ttc")

a = ["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5:最后的骑士","摔跤吧!爸爸","加勒比海盗5:死无对证","金刚:骷髅岛","极限特工:终极回归","生化危机6:终章","乘风破浪","神偷奶爸3","智取威虎山","大闹天竺","金刚狼3:殊死一战","蜘蛛侠:英雄归来","悟空传","银河护卫队2","情圣","新木乃伊",]

b=[56.01,26.94,17.53,16.49,15.45,12.96,11.8,11.61,11.28,11.12,10.49,10.3,8.75,7.55,7.32,6.99,6.88,6.86,6.58,6.23]

#设置图形大小
plt.figure(figsize=(20,8),dpi=80)

#条形图
plt.barh(range(len(a)),b,height=0.3,color="orange")

#横坐标
plt.yticks(range(len(a)),a,fontproperties=my_font)

plt.grid(alpha=0.3)

plt.show()
from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager.FontProperties(fname="C:/Windows/Fonts/msyh.ttc")

a = ["猩球崛起","敦刻尔克","蜘蛛侠","战狼2"]
b_16 = [15746,312,4497,319]
b_15 = [12357,156,2045,168]
b_14 = [2358,399,2358,362]

bar_width = 0.2

x_14 = list(range(len(a)))
x_15 = [i+bar_width for i in x_14]
x_16 = [i+bar_width*2 for i in x_14]
#设置图形大小
plt.figure(figsize=(20,8),dpi=80)

#条形图
plt.bar(range(len(a)),b_14,width=bar_width,label="9.14")
plt.bar(x_15,b_15,width=bar_width,label="9.15")
plt.bar(x_16,b_16,width=bar_width,label="9.16")
plt.xticks(x_15,a,fontproperties=my_font)

#图例
plt.legend(prop=my_font)
plt.show()
from matplotlib import pyplot as plt
from matplotlib import font_manager

interval = [0,5,10,15,20,25,30,35,40,45,60,90]
width = [5,5,5,5,5,5,5,5,5,15,30,60]
quantity = [836,2737,3723,3926,3596,1438,3273,642,824,613,215,47]


plt.figure(figsize=(20,8),dpi=80)
plt.bar(range(len(quantity)),quantity,width=1)

_x = [i-0.5 for i in range(13)]
_xtick_labels = interval+[150]
plt.xticks(_x,_xtick_labels)

plt.grid(alpha=0.4)
plt.show()

ECHARTS
plotly

未经允许不得转载:作者:1430-王同学, 转载或复制请以 超链接形式 并注明出处 拜师资源博客
原文地址:《绘制散点图》 发布于2020-12-10

分享到:
赞(0) 打赏

评论 抢沙发

评论前必须登录!

  注册



长按图片转发给朋友

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

Vieu3.3主题
专业打造轻量级个人企业风格博客主题!专注于前端开发,全站响应式布局自适应模板。

登录

忘记密码 ?

您也可以使用第三方帐号快捷登录

Q Q 登 录
微 博 登 录