2020/8/14数据分析2

这里写自定义目录标题

加标签

1.plt.legend
-plt.plot(lanel=)
-局部设置字体prop=font
2.文本注释(设置标签)
-plt.annotate(text,xy,xytext,arrowprops = {“”:2})
text:需要注释的文本,字符串
xy:需要注释的坐标
xytext:注释文本所加在的位置
arrowprops:设置箭头,字典形式```

#绘制散点图
plt.scatter(x,y)

#条形图
1.柱状图:plt.bar(x,height)
2.条形图:plt.barh(y,whidth)


##练习
练习1
为了对某一产品进行合理定价,我们对此类商品进行了试销实验,价格与需求量数据如下。利用图表分析规律。
价格
60
80
40
30
70
90
95
需求量
100
50
120
135
65
45
40
price = [60,80,40,30,70,90,95]
sales = [100,50,120,135,65,45,40]

```python
import matplotlib.pyplot as plt
p = [60,80,40,30,70,90,95]
s = [100,50,120,135,65,45,40]
plt.scatter(p,s)
plt.show()
```![在这里插入图片描述](https://img-blog.csdnimg.cn/20200815172845735.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3lhb2ppbmdfYmFieQ==,size_16,color_FFFFFF,t_70#pic_center)

练习2
电影数据如下:
movies_name = ["变身特工","美丽人生","鲨海逃生","熊出没·狂野大陆"] 
day_12 = [2358,399,2358,362] 
day_13 = [12357,156,2045,168] 
day_14 = [15746,312,4497,319]
需求:
• 直观体现出不同电影近三天的票房的对比情况

```python
movies_name = ["变身特工","美丽人生","鲨海逃生","熊出没·狂野大陆"] 
day_12 = [2358,701,2200,362] 
day_13 = [6888,502,2045,208] 
day_14 = [8368,312,4497,120]

plt.figure(figsize=(14,8))

# 设置x轴为 movies_name对应索引位置
movies_po = range(len(movies_name))

# 定义柱子宽度
width = 0.2

# 如果需要 12放左边 13放中间 14放右边 则:13不变; 12往左边挪0.2; 14往右边挪0.2..... 
po_l = [i-0.2 for i in movies_po]
plt.bar(po_l,day_12,width=width,label="12号",color="r")

po_c = movies_po
plt.bar(po_c,day_13,width=width,label="13号",color="g")

po_r = [i+0.2 for i in movies_po]
plt.bar(po_r,day_14,width=width,label="14号",color="b")

# 设置刻度 为movies_name
plt.xticks(movies_po,movies_name,fontproperties=font)

# 设置图例
plt.legend(prop=font)

# 设置数据标签
def auto_label(x_po,y_po):
    for x_i,y_i in zip(x_po,y_po):
        plt.annotate(f"{(y_i)}",xy=(x_i,y_i),xytext=(x_i,y_i+50))

auto_label(po_l,day_12)
auto_label(po_c,day_13)
auto_label(po_r,day_14)

# 设置标签与标题
plt.xlabel("电影",fontproperties=font)
plt.ylabel("票房",fontproperties=font)
plt.title("2020年12日至14日电影票房",fontproperties=font)

plt.show()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值