2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
#Line chart इत्यस्य उपयोगः दत्तांशस्य परिवर्तनस्य प्रतिनिधित्वार्थं भवति
plt.plot(x,y) ९.
#हिस्टोग्रामस्य उपयोगः निरन्तरदत्तांशगणनाय भवति न अन्तरम्
plt.hist(दत्तांशसरणिका, समूहानां संख्या)
#Bar chart इत्यस्य उपयोगः असततसरणयः गणयितुं तेषां परिवर्तनं प्रतिबिम्बयितुं च भवति अन्तरं भवति
plt.bar(x,y,चौड़ाई = 0.3)
plt.barh(y,x,उच्चता = 0.3)
xy अक्षस्य मध्ये सम्बन्धप्रवृत्तिं दर्शयितुं #Scatter plot इत्यस्य उपयोगः भवति
plt.प्रकीर्णन(x,y) 1.1.
- #导入pyplot
- from matplotlib import pyplot as plt
- #限制大小和像素
- plt.figure(figsize = (20,8),dpi = 80)
-
- #数据集中对应的x坐标 是一个迭代对象
- x = rnage(2,26,2)#共12个数据
- #数据集中对应的y坐标 是一个迭代对象
- y = [15,13,14.5,17,20,25,26,26,24,22,18,15]#共12个数据
- #x和y组成了12个数据点
-
- #绘制x轴的刻度
- plt.xticks( range(2,25,1) )
- #plt.xticks(x)
- #plt.xticks( [i/2 for i in range(2,49)] )
-
- #绘制y轴的刻度
- plt.yticks( range(min(y),max(y)+1 )
-
- #传入x y 通过plot绘制折线图
- plt.plot(x,y)
-
- #保存
- plt.savefig("./t1.png")
-
- #展示图形
- plt.show()
- from matplotlib import pyplot as plt
- import random
-
- #设置字体参数
- font = {
- 'family' : 'YouYuan',
- 'weight' : 'bold',
- 'size' : 12
- }
-
- #将字体参数应用到全局
- plt.rc('font',**font)
-
- #设置数据集的x y坐标
- x = range(0,120)#共120个数(分钟)
- y = [ random.randint(20,35) for i in range(120) ]
-
- #设置图形大小
- plt.figure( figsize = (20,8),dpi = 60 )
-
- #设置刻度
- #分别表示开始的位置和结束的位置(不包括)和步长
- _x = x[::10]#表示每10分钟为1个刻度
- _xtick_labels = ["现在是{}时{}分".format(i//60 + 10,i%60) for i in _x]
- #刻度集合 刻度值 旋转程度
- plt.xticks(_x,_xtick_labels,rotation = -90)
-
- #绘制图片
- plt.plot(x,y)
-
- #绘制网格 设置透明度
- plt.grid(alpha=0.3)
-
- #设置标签
- plt.xlabel("时间")
- plt.ylabel("温度 单位(C)",labelpad = 20)#偏移
- plt.tile("10点到12嗲每分钟的气温变化情况")
-
- #展示图片
- plt.show()
- #coding = utf-8
- from matplotlib import pyplot as plt
- from matplotlib import font_manager
- font = {
- 'family':'YouYuan'
- 'weight':'bold'
- 'size':12
- }
- plt.rc('font',**font)
-
- #give the data
- y_1 = [1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1]
- y_2 = [1,0,3,1,2,2,3,3,2,1,2,1,1,1,1,1,1,1,1,1]
- x = range(11,31)
-
- #set the size of the graph
- plt.figure(figsize=(20,8),dpi=80)
-
- #set the scale of axis x and axis y
- _x = x
- _xticks_labels = ["{}岁".format(i) for i in _x]
- plt.xticks(_x,_xticks_labels)#data from(data numbers) format
- plt.yticks(range(0,7))
-
- #draw the picture respectively
- plt.plot(x,y_1,label = "自己",color = "orange",linestyle = ":")
- plt.plot(x,y_2,label = "同桌",color = "cyan",linestyle = "--")
-
- #set the grid and the tansparency
- plt.grid(alpha = 0.3,color = "black",linestyle = "dotted")#color can be #00ff00
-
- #put the position of the legend
- plt.legend(loc="upper left")
-
- #draw the picture
- plt.show()
- #coding = utf-8
- from matplotlib import pyplot as plt
- from matplotlib import font_manager
- font = {
- 'family':'YouYuan',
- 'weight':'bold',
- 'size' :10
- }
- plt.rc("font",**font)
-
- #give the data
- x_3 = range(1,29)
- 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,19,21,22,23]#28 numbers
- x_10 = range(51,82)
- 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] #31 numbers
-
- plt.figure(figsize=(20,8),dpi=80)
-
- #in order to put the seperate x together put the data to 2 sides
- _x = list(x_3)+list(x_10)
-
- #use scatter to draw the picture
- plt.scatter(x_3,y_3,label = "March")
- plt.scatter(x_10,y_10,label = "Octomber")
-
- #give the scale of axis x
- _xtick_labels = ["3月{}日".format(i) for i in x_3]
- _xtick_labels += ["10月{}日".format(i) for i in x_10]
- plt.xticks(_x[::3],_xtick_labels[::3],rotation = 45)#every 3 days is one scale
-
- #add the position of legend
- plt.legend(loc="upper right")
- #add the descreptive information
- plt.xlabel("时间")
- plt.ylabel("温度")
- #add grid
- plt.grid(alpha = 0.4)
- #show the picture
- plt.show()
- from matplotlib import pyplot as plt
- from matplotlib import font_manager
- font ={
- 'family':'YouYuan',
- 'weight':'bold',
- 'size':10
- }
- plt.rc("font",**font)
- #You can make it more tidy by adding n to the same position
- a = ["电影1n111","电影2","电影3n2","电影3n34","电影5n4","电影6n4","电影6n66667","电影8","电影9","电影1n0","电影1n1","电影1n2","电影1n3","电影1n4","电影1n5","电影1n6","电影1n7","电影1n8"]
- b = [56.01,26.94,17.53,16.49,15.45,12.96,11.8,41.21,32.34,22.23,77.7,88.8,12,14,16,1,19,33]
- plt.figure(figsize=(20,15),dpi=80)
-
- #draw the bar picture
- #if You want to change the pisition of x and y just do the tips 1 and 2
- plt.bar(a,b,width = 0.3)
- #1. plt.barh(a,b,height = 0.3)
-
- #fix the scale of x
- _xtick_labels = [i for i in a]
- plt.xticks(a,_xtick_labels,rotation = 60)
- #2.plt.yticks(a,_xtick_labels,rotation = 60)
-
- plt.show()
-
-
- #coding = utf-8
- from matplotlib import pyplot as plt
- from matplotlib import font_manager
- font = {
- 'family':'YouYuan',
- 'weight':'bold',
- 'size':10
- }
-
- #give the data axis x and y
- a = ["猩球崛起3:终极之战","敦刻尔克","蜘蛛侠:英雄归来","战狼2"]
- b_14 = [2358,399,2358,362]
- b_15 = [12357,156,2045,168]
- b_16 = [15746,312,4497,319]
-
- #set the size of the graphic
- plt.figure(figsize=(20,8),dpi=80)
-
- #change the pos of the scale
- x_14 = range(len(a))
- x_15 = [i+bar_width for i in x_14]#clost to just right
- x_16 = [i+bar_width for i in x_15]
-
-
- #trans the data collections into
- plt.bar(x_14,b_14,width = bar_width,label="14日")#first one is scale
- plt.bar(x_15,b_15,width = bar_width,label="15日")
- plt.bar(x_16,b_16,width = bar_width,label="16日")
-
- plt.legend(loc="upper left")
-
- #give the scale parameters
- plt.xticks(x_15,a)
-
- plt.show()
- from matplotlib import pyplot as plt
- from matplotlib import font_manager
- import random
- font = {
- 'family':'YouYuan',
- 'weight':'bold',
- 'size':1
- }
- random.seed(0)
- a = [random.randint(70,154) for i in range(120)]
- a.append(160)
- a.append(60)
-
- plt.figure(figsize = (20,80),dpi = 80)
-
- #calculation 1.组数==极差/组距 2.组距==极差/组数
- #1.
- #fix the num_bins then calculate the distance
- #tip: the (max(a)-min(a))/num_bins must == 0
- num_bins=20
- d = (max(a)-min(a))//num_bins
- #draw the picture
- plt.hist(a,num_bins)#原始数组a和分组
-
- #fix the scale of axis a
- plt.xticks(range(min(a),max(a)+d,d))
-
- plt.grid()
- plt.show()
-
-
- import random
- from matplotlib import pyplot as plt
- from matplotlib import font_manager
- font = {
- 'family':'YouYuan',
- 'weight':'bold',
- 'size':1
- }
- random.seed(0)
- a = [random.randint(70,154) for i in range(120)]
- a.append(160)
- a.append(60)
- plt.figure(figsize = (20,80),dpi = 80)
- #计算组数 组数==极差/组距
- #将hist中第2个参数的值写为plt.xticks中的值 然后组距可以随便调
- #其实就是一个刻度就是一组 然后用d的值分出来所需要的组数
- d = 5
- plt.hist(a,range(min(a),max(a)+d,d))#原始数组a和分组
- #设置x轴的刻度
- plt.xticks(range(min(a),max(a)+d,d))#刚好包含max(a)
- #画网格
- plt.grid()
- plt.show()
- #coding=UTF-8
- from matplotlib import pyplot as plt
- from matplotlib import font_manager
- #这是统计过的所以用bar条形图 不连在一起
- #没有统计过用hist直方图 连在一起
- 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.bar(range(len(quantity)),quantity,width=1)#width为1可以让条形图连在一起
- #设置x轴的刻度
- _x = [i*0.5 for i in range(len(interval)+1)]# 分成了多少份
- _xtick_labels = interval+[150] #额外加上一个元素
- plt.xticks(_x,_xtick_labels)
- plt.grid(alpha = 0.4)
- plt.show()