首页 > 其他分享 >画图之小试牛刀

画图之小试牛刀

时间:2023-02-26 21:44:56浏览次数:35  
标签:plt 20 title 画图 3142 fontsize data 小试牛刀

import pandas as pd
import matplotlib.pyplot as plt
catering_sale = "./data/catering_sale.xls"
data = pd.read_excel(catering_sale, index_col = '日期')
# print(data.describe())
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.figure()
p = data.boxplot(return_type = 'dict')
x = p['fliers'][0].get_xdata()
y = p['fliers'][0].get_ydata()
y.sort()
for i in range(len(x)):
if i > 0:
plt.annotate(y[i], xy = (x[i],y[i]), xytext=(x[i] + 0.05 - 0.8 / (y[i] - y[i-1]), y[i]))
else:
plt.annotate(y[i], xy = (x[i],y[i]), xytext=(x[i] + 0.08, y[i]))
plt.title('3142',fontsize=20)
plt.show()

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
catering_sale = "./data/catering_fish_congee.xls"
data = pd.read_excel(catering_sale, names=['date','sale'])
bins = [0,500,1000,1500,2000,2500,3000,3500,4000]
labels = ['[0,500)','[500,1000)','[1000,1500)','[1500,2000)','[2000,2500)',
'[2500,3000)','[3000,3500)','[3500,4000)']
data['sale分层'] = pd.cut(data.sale, bins, labels=labels)
aggResult = data.groupby(by=['sale分层'])['sale'].agg(sale=np.size)
pAggResult = round(aggResult/aggResult.sum(),2) * 100
plt.figure(figsize=(10,6))
pAggResult['sale'].plot(kind='bar',width=0.8,fontsize=10)
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.title('3142',fontsize=20)
plt.show()

import pandas as pd
import matplotlib.pyplot as plt
catering_dish_profit = './data/catering_dish_profit.xls'
data = pd.read_excel(catering_dish_profit)
x = data['盈利']
labels = data['菜品名']
plt.figure(figsize=(8,6))
plt.pie(x,labels=labels)
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.title('3142',fontsize=20)
plt.axis('equal')
plt.show()
x = data['菜品名']
y = data['盈利']
plt.figure(figsize=(8,4))
plt.bar(x,y)
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.xlabel('菜品')
plt.ylabel('销量')
plt.title('3142',fontsize=20)
plt.show()

 

import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_excel("./data/dish_sale.xls")
plt.figure(figsize=(8,4))
plt.plot(data['月份'],data['A部门'],color='green',label='A部门',marker='o')
plt.plot(data['月份'],data['B部门'],color='red',label='B部门',marker='s')
plt.plot(data['月份'],data['C部门'],color='skyblue',label='C部门',marker='x')
plt.legend()
plt.ylabel('销售额(万元)')
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.title('3142',fontsize=20)
plt.show()
data = pd.read_excel("./data/dish_sale_b.xls")
plt.figure(figsize=(8,4))
plt.plot(data['月份'],data['2012年'],color='green',label='2012年',marker='o')
plt.plot(data['月份'],data['2013年'],color='red',label='2013年',marker='s')
plt.plot(data['月份'],data['2014年'],color='skyblue',label='2014年',marker='x')
plt.legend()
plt.ylabel('销售额(万元)')
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.title('3142',fontsize=20)
plt.show()

 

import pandas as pd
import matplotlib.pyplot as plt
df_normal = pd.read_csv("./data/user.csv")
plt.figure(figsize=(8,4))
plt.plot(df_normal["Date"],df_normal["Eletricity"])
plt.xlabel("日期")
x_major_locator = plt.MultipleLocator(7)
ax = plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
plt.ylabel("每日电量")
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.title('3142',fontsize=20)
plt.show()
df_steal = pd.read_csv("./data/Steal user.csv")
plt.figure(figsize=(10,9))
plt.plot(df_steal["Date"],df_steal["Eletricity"])
plt.xlabel("日期")
x_major_locator = plt.MultipleLocator(7)
ax = plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
plt.ylabel("每日电量")
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.title('3142',fontsize=20)
plt.show()

)
       

import pandas as pd
import matplotlib.pyplot as plt
dish_profit = './data/catering_dish_profit.xls'
data = pd.read_excel(dish_profit,index_col='菜品名')
data = data['盈利'].copy()
data.sort_values(ascending=False)
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.figure()
data.plot(kind='bar')
plt.ylabel('盈利(元)')
p = 1.0 * data.cumsum()/data.sum()
p.plot(color='r',secondary_y=True,style='-o',linewidth=2)
plt.annotate(format(p[6], '.4%'), xy=(6, p[6]),
xytext=(6 * 0.9, p[6] * 0.9), arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2"))
plt.ylabel('盈利(比例)')
plt.title('3142',fontsize=20)
plt.show()

import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(7,5))
plt.rcParams['axes.unicode_minus'] = False
x = np.linspace(0,2*np.pi,50)
y = np.sin(x)
plt.plot(x,y,'bp--')
plt.title('3142',fontsize=20)
plt.show()

import matplotlib.pyplot as plt
labels = 'Frogs','Hogs','Dogs','Logs'
sizes = [15,30,45,10]
colors = ['yellowgreen','gold','lightskyblue','lightcoral']
explode = (0,0.1,0,0)
plt.pie(sizes,explode=explode,labels=labels,colors=colors,autopct='%1.1f%%',shadow=True,startangle=90)
plt.axis('equal')
plt.title('3142',fontsize=20)
plt.show()

import matplotlib.pyplot as plt
import numpy as np
x = np.random.randn(1000)
plt.hist(x,10)
plt.title('3142',fontsize=20)
plt.show()

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
x = np.random.randn(1000)
D = pd.DataFrame([x,x+1]).T
D.plot(kind='box')
plt.title('3142',fontsize=20)
plt.show()

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
x = pd.Series(np.exp(np.arange(20)))
plt.figure(figsize=(8,9))
ax1 = plt.subplot(2,1,1)
plt.title('3142',fontsize=20)
x.plot(label='原始数据图',legend=True)
ax1 = plt.subplot(2,1,2)
plt.title('3142',fontsize=20)
x.plot(logy=True,label='对数数据图',legend=True)
plt.show()

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
error = np.random.randn(10)
y = pd.Series(np.sin(np.arange(10)))
y.plot(yerr=error)
plt.title('3142',fontsize=20)
plt.show()

画图往往离不开matplotlib,numpy,pandas,学会运用这些才能更好更便捷画出想要的图。

标签:plt,20,title,画图,3142,fontsize,data,小试牛刀
From: https://www.cnblogs.com/zhulol/p/17157840.html

相关文章

  • python数据分析画图
    importnumpyasnpimportpandasaspdimportmatplotlib.pyplotaspltpath='./data/catering_sale.xls'data=pd.read_excel(path,index_col=u'日期')#读取......
  • 应用Python进行统计数据画图
     画饼图:#-*-coding:utf-8-*-"""SpyderEditorThisisatemporaryscriptfile."""importpandasaspdimportnumpyasnp#importseabornasimportmatplotli......
  • 画图
    importpandasaspdimportnumpyasnpcatering_sale='E:/data/catering_fish_congee.xls'#餐饮数据data=pd.read_excel(catering_sale,names=['date','sale']......
  • python数据处理画图基础
    引入常用的python库importpandasaspdimportnumpyasnpimportmatplotlib.pyplotaspltcatering_sale=r'G:\WECHAT\WeChatFiles\wxid_op0z9xixesag22\FileStorag......
  • python 画图 chap3
    importmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['SimHei']plt.rcParams['axes.unicode_minus']=Falseplt.figure()p=data.boxplot(return_type='dict'......
  • Luban小试牛刀.md
    Luban小试牛刀LubanUnityLubanUnity配置工具配置解决方案简介Github文档视频教程Unity工具个人感觉挺强大,便捷的,适合中大型游戏项目的配置工作。小项目scriptobjec......
  • echarts 画图报错 this.dom.getContext is not a function
      我给 <el-card>绑定了ref,利用$refs获取echarts实例 constecharts1=echarts.init(this.$refs.echarts1);结果报错了解决办法:<el-cardstyle="width:100%;......
  • Qt实现画图工具
    #include<QtWidgets>#include"mainwindow.h"#include"scribblearea.h"//![0]MainWindow::MainWindow(){scribbleArea=newScribbleArea;setCentralWidget(scr......
  • pycharm中matplotlib 画图后图片卡住问题的解决
    目录问题解决方案本质理解问题以前使用pycharmpythonmatplotlib画图的时候,可以画好多可以交互的图,像matlab一样,但从某一时刻开始,pycharm设置改了哪里,只要使用matplotl......
  • 一笔画图形的判断方式
    一、笔画的概念1、一笔画是讨论某图形是否可以一笔画出。图形中任何端点根据所连接线条数被分为奇点、偶点。只有所有点为偶点的图形和只有两个奇点的图形一定可以一笔画......