
Matplotlib
书院二层楼
这个作者很懒,什么都没留下…
展开
-
matplotlib饼图(pie、explode、shadow、labeldistance)
代码示例:# 5. 绘制饼图import matplotlib.pyplot as pltimport matplotlibfrom matplotlib import font_managermy_font = font_manager.FontProperties(fname='./STSONG.TTF',size=10)label_list = ["第一部分", "第二部分", "第三部分"] # 各部分标签size = [55, 35, 10] # 各部分大小col原创 2020-12-29 21:31:10 · 7485 阅读 · 0 评论 -
matplotlib直方图(hist、bins、组距、组数)
代码示例:#统计电影时长的分布状态movies_time = [131,98, 125, 131, 124, 139, 131, 117, 128, 108, 135, 138, 131, 102, 107, 114, 119, 128, 121, 142, 127, 130, 124, 101, 110, 116, 117, 110, 128, 128, 115, 99, 136, 126, 134, 95, 138, 117, 111,78, 132, 12原创 2020-12-29 21:25:32 · 8015 阅读 · 0 评论 -
matplotlib罗列条形图(bottom)
代码示例:import matplotlib.pyplot as pltimport matplotlib.font_manager as fmimport numpy as npindex = np.arange(4)TJ = [30,66,54,45]BJ = [70,56,64,35]my_font = fm.FontProperties(fname='/System/Library/Fonts/PingFang.ttc',size=10)plt.bar(index,TJ,wid原创 2020-12-29 21:10:33 · 669 阅读 · 0 评论 -
matplotlib并列条形图(bar、width)
代码示例:import matplotlib.pyplot as pltimport matplotlib.font_manager as fmimport numpy as npindex = np.arange(4)TJ = [30,66,54,45]BJ = [70,56,64,35]my_font = fm.FontProperties(fname='/System/Library/Fonts/PingFang.ttc',size=10)plt.bar(index,TJ,wid原创 2020-12-29 21:06:25 · 1766 阅读 · 0 评论 -
matplotlib横向条形图(barh、get_width、get_y)
代码示例:import matplotlib.pyplot as pltimport matplotlib.font_manager as fmmy_font = fm.FontProperties(fname='/System/Library/Fonts/PingFang.ttc',size=10)a = ['流浪地球', '疯狂的外星人','飞驰人生','大黄蜂','熊出没.原始时代','新喜剧之王']b = [38.13, 19.85, 14.89, 11.36,6.47,5.93]原创 2020-12-29 20:52:39 · 2926 阅读 · 0 评论 -
matplotlib绘制条形图(bar、设置不同的颜色、设置每个条形图文字)
代码示例:'''绘制电影票房条形图a = ['流浪地球', '疯狂的外星人','飞驰人生','大黄蜂','熊出没.原始时代','新喜剧之王']b = ['38.13', '19.85', '14.89', '11.36','6.47','5.93']'''import matplotlib.pyplot as pltimport matplotlib.font_manager as fma = ['流浪地球', '疯狂的外星人','飞驰人生','大黄蜂','熊出没.原始时代','新喜剧原创 2020-12-22 21:38:28 · 23335 阅读 · 2 评论 -
matplotlib绘制散点图(scatter)
代码示例:'''4月份每天的最高气温a=[12,16,11,12,11,12,6,6,7,18,9,12,15,14,17,18,21,16,17,25,14,15,15,15,19,21,22,22,22,23]'''import matplotlib.pyplot as pltimport matplotlib.font_manager as fmx = range(1,31)y = [12,16,11,12,11,12,6,6,7,18,9,12,15,14,17,18,21,1原创 2020-12-22 21:20:13 · 373 阅读 · 0 评论 -
matplotlib(改变坐标轴的默认显示方式:set_color、set_position)
代码示例:import matplotlib.pyplot as plty = range(0,14,2)x = [-3,-2,-1,0,1,2,3]#获取当前图表的图像pic = plt.gca()#设置图像的包围线pic.spines['right'].set_color('none')pic.spines['top'].set_color('none')pic.spines['left'].set_color('blue')pic.spines['bottom'].set_原创 2020-12-22 21:05:40 · 1843 阅读 · 0 评论 -
matplotlib折线(截取坐标系)
代码示例:import matplotlib.pyplot as pltimport numpy as npx = np.arange(-10,11,1)y = x**2plt.plot(x,y)#plt.xlim([-5,5]) #截取x轴左右两边#plt.xlim(xmin=-4) #截取x轴左边#plt.xlim(xmax=4) #截取x轴右边plt.ylim(ymin=0)plt.xlim(xmin=0)plt.show()效果截图:...原创 2020-12-22 20:53:04 · 955 阅读 · 0 评论 -
matplotlib折线图(一图多个坐标系子图)
代码示例:import matplotlib.pyplot as pltimport numpy as npx = np.arange(1,100)fig = plt.figure(figsize=(20,10),dpi=80)# 创建子图1sub1 = fig.add_subplot(2,2,1)sub1.plot(x,x)#创建子图2sub2 = fig.add_subplot(2,2,2)sub2.plot(x,x**2)sub2.grid(color='r',lines原创 2020-12-22 20:38:50 · 1190 阅读 · 0 评论 -
matplotlib折线图(图例-legend、网格-grid)
代码示例:import randomfrom matplotlib import pyplot as pltfrom matplotlib import font_managery1 = [0,0,1,1,2,4,3,4,4,5,6,5,4,3,3,1,1,8,1,1]y2 = [0,1,3,1,2,2,3,4,3,2,1,2,1,1,1,6,1,1,1,1]x = range(11,31)plt.figure(figsize=(20,8),dpi=80)plt.plot(x,y1,c原创 2020-12-22 17:27:34 · 2848 阅读 · 0 评论 -
matplotlib折线图(字体设置-FontProperties、轴信息设置-x/ylabel、标题设置)
代码示例:'''matplot1ib只显示英文,无法显示中文,需要修改matplot1ib的默认字体。通过matp7otlib下的font_ manager 可以解决'''import randomfrom matplotlib import pyplot as pltfrom matplotlib import font_managerx = range(0,120)y = [random.randint(25,45) for i in range(120)]plt.figure(原创 2020-12-22 16:24:37 · 2587 阅读 · 1 评论 -
matplotlib折线图(x/y轴刻度、刻度标签、标签旋转)
代码示例:import randomfrom matplotlib import pyplot as pltx = range(2,26,2) y = [random.randint(12,35) for i in x]plt.figure(figsize=(20,8),dpi=80)# 设置x轴的刻度# plt.xticks(x)# 设置y轴的刻度# plt.yticks(range(min(y),max(y)+1))# 构造x轴刻度标签xticks_label = [f"原创 2020-12-22 15:12:00 · 8709 阅读 · 0 评论 -
matplotlib折线图(设置图片大小和图片保存)
代码示例:from matplotlib import pyplot as pltx = range(1,10) #x轴的位置y = [6,7,12,12,15,17,15,20,18] #y轴的位置'''画布对象中设置图片的大小figsize:指定figure的宽和高,单位为英寸;dpi参数指定绘图对象的分辨率,即每英寸多少个像素,缺省值为801英寸等于2.5cm, A4纸是21* 30cm的纸张'''plt.figure(figsize=(20,8),dpi=90)#传入x,y原创 2020-12-21 16:31:36 · 6561 阅读 · 0 评论 -
matplotlib折线图(标记点、标记点大小、标记点边颜色、标记点边宽)
代码示例:from matplotlib import pyplot as pltx = range(1,10) #x轴的位置y = [6,7,12,12,15,17,15,20,18] #y轴的位置#传入x,y,通过plot画图,并设置折线颜色、透明度、折线样式和折线宽度 标记点、标记点大小、标记点边颜色、标记点边宽plt.plot(x,y,color='red',alpha=0.3,linestyle='--',linewidth=5,marker='o' ,marke原创 2020-12-21 16:21:19 · 54769 阅读 · 0 评论 -
matplotlib折线图(折线颜色、透明度、折线样式和折线宽度)
代码实例:from matplotlib import pyplot as pltx = range(1,10) #x轴的位置y = [6,7,12,12,15,17,15,20,18] #y轴的位置#传入x,y,通过plot画图,并设置折线颜色、透明度、折线样式和折线宽度plt.plot(x,y,color='red',alpha=0.3,linestyle='--',linewidth=5)plt.show'''基础属性设置color='red' :折线的颜色a1pha=0.5原创 2020-12-21 16:06:28 · 6407 阅读 · 0 评论 -
初试Matplotlib画图
'''Matplotlib是一个Python 2D绘图库,它以多种硬拷贝格式和跨平台的交互式环境生成出版物质量的图形python -m pip install -U pippython -m pip install -U matplotlib'''import matplotlib.pyplot as plt#jupyter首次运行不显示图片解决办法%matplotlib inline #传入x,y,通过plot画图plt.plot([8,6,9],[5,6,7])#在执行程序时展.原创 2020-12-21 15:15:55 · 131 阅读 · 0 评论