2021-1-5 作业

在这里插入图片描述

from matplotlib import pyplot as plt
# 注意FontProperties首字母大写
from matplotlib.font_manager import FontProperties
# 设置字体
font = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=10)

x = [60,80,40,30,70,90,95]
y = [100,50,120,135,65,45,40]

plt.scatter(x,y,marker='*',color='purple')

# 定义X轴刻度,标签
x_t = range(0,int(max(x)+10))[::10]
x_l = ['{}元'.format(i) for i in x_t]
plt.xticks(x_t,x_l,fontproperties=font)

# 定义x轴标签
plt.xlabel('价格',fontproperties=font)

# 定义y轴刻度,标签
y_t = range(0,int(max(y)+10))[::10]
y_l = [i for i in y_t]
plt.yticks(y_t,y_l)

# 定义y轴标签
plt.ylabel('需求量',fontproperties=font)

# 定义一个空列表z
aa = []

# 定义点的坐标

for a,b in zip(x,y):
    # print(a,b)
    # 通过plt.text()绘制点的值,前两个参数是值的坐标,可以进行加减改变位置
    # center垂直居中显示,bottom水平靠下显示
    plt.text(a,b-6,s=(a,b),ha='center',va='bottom',fontsize=8)

    # 分析数据
    # 商家必然会追求最大利润
    aa.append(a*b)

# 创建图例
plt.legend(['价格供需变化'],prop=font)

# 设置图表标题
plt.title('价格供需变化图',fontproperties=font,color='red',fontsize=12)

for i in range(7):
    if x[i]*y[i] == max(z):
        print('商家应当选择价格为{}需求量为{}的产品。'.format(x[i],y[i]))




# 显示绘图结果
plt.show()

在这里插入图片描述

from matplotlib import pyplot as plt

# 设置字体
font = {
	‘family’:‘SimHei’,
	‘weight’:‘bold’,
	‘size’:10
}

movies_name = ["变身特工","美丽人生","鲨海逃生","熊出没·狂野大陆"]
day_12 = [2358,399,2358,362]
day_13 = [12357,156,2045,168]
day_14 = [15746,312,4497,319]

# 设定条状图宽度
width=0.3

# 定义柱子颜色
# color=['r','g','b']

# 设定x轴
d1 = [i - width for i in range(len(day_12))]
d2 = range(len(day_13))
d3 = [i + width for i in range(len(day_14))]


plt.bar(d1,day_12,width=width,align='center',orientation='vertical',color='r')
plt.bar(d2,day_13,width=width,align='center',orientation='vertical',color='g')
plt.bar(d3,day_14,width=width,align='center',orientation='vertical',color='b')

# 设置x轴刻度
plt.xticks(range(len(day_12)),movies_name,fontproperties=font)

# 设置x轴标签
plt.xlabel('电影名称',fontproperties=font,fontsize=12)


# 设置y轴的标签
plt.ylabel('票房',fontproperties=font,fontsize=12)

# 柱子
def bar0(d_num,day_num):

    for a,b in zip(d_num,day_num):
        plt.text(a,b+5,s=b,ha='center',va='bottom',fontsize=8)

bar0(d1,day_12)
bar0(d2,day_13)
bar0(d3,day_14)

# 图例
plt.legend(['12日票房','13日票房','14日票房'],prop=font)

# 设置图标标题
plt.title('电影票房对比表',fontproperties=font,fontsize=15,fontweight='bold',backgroundcolor='gold',alpha=0.8)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值