Python数据可视化之matplotlib实践 源码 第一篇 入门 第三章
2021-01-22 06:15
标签:min hide unicode span 第三章 plane ace onclick 不同 图3.1
================================================ 图3.2
================================================ 图 3.3
================================================ 图 3.4 ================================================ 图 3.5 ================================================ 图 3.6 ================================================ 图 3.7 ================================================ 图 3.8 ================================================ 图 3.9 ================================================ 图 3.10 ================================================ 图 3.11 ================================================ 图 3.12 ================================================ 图 3.14 ================================================ 图 3.15 ================================================ 图 3.16 ================================================ 图 3.17 ================================================ Python数据可视化之matplotlib实践 源码 第一篇 入门 第三章 标签:min hide unicode span 第三章 plane ace onclick 不同 原文地址:https://www.cnblogs.com/devilmaycry812839668/p/12890456.htmlimport matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
x=[1,2,3,4,5]
y=[6,10,4,5,1]
plt.grid(True, axis=‘y‘,ls=‘:‘,color=‘r‘,alpha=0.3)
plt.bar(x,y,align=‘center‘, color=‘b‘, tick_label=[‘A‘,‘B‘,‘C‘,‘D‘,‘E‘],
alpha=0.6, edgecolor="black")
plt.xlabel(‘测试难度‘)
plt.ylabel(‘试卷份数‘)
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
x=[1,2,3,4,5]
y=[6,10,4,5,1]
plt.grid(True, axis=‘x‘,ls=‘:‘,color=‘r‘,alpha=0.3)
plt.barh(x,y,align=‘center‘, color=‘c‘, tick_label=[‘A‘,‘B‘,‘C‘,‘D‘,‘E‘],
alpha=0.6, edgecolor="black")
plt.ylabel(‘测试难度‘)
plt.xlabel(‘试卷份数‘)
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
x=[1,2,3,4,5]
y=[6,10,4,5,1]
y1=[2,6,3,8,5]
plt.bar(x,y,align=‘center‘,color=‘#66c2a5‘, tick_label=[‘A‘,‘B‘,‘C‘,‘D‘,‘E‘],
label=‘班级A‘, edgecolor=‘black‘)
plt.bar(x,y1,align=‘center‘,color=‘#8da0cb‘, bottom=y,
label=‘班级B‘, edgecolor=‘black‘)
plt.xlabel("测试难度")
plt.ylabel("测试份数")
plt.legend()
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
x=[1,2,3,4,5]
y=[6,10,4,5,1]
y1=[2,6,3,8,5]
plt.barh(x,y,align=‘center‘,color=‘#66c2a5‘, tick_label=[‘A‘,‘B‘,‘C‘,‘D‘,‘E‘],
label=‘班级A‘, edgecolor=‘black‘)
plt.barh(x,y1,align=‘center‘,color=‘#8da0cb‘, left=y,
label=‘班级B‘, edgecolor=‘black‘)
plt.ylabel("测试难度")
plt.xlabel("测试份数")
plt.legend()
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
x=np.array([1,2,3,4,5])
y=[6,10,4,5,1]
y1=[2,6,3,8,5]
bar_width=0.35
tick_label=[‘A‘,‘B‘,‘C‘,‘D‘,‘E‘]
plt.bar(x, y, bar_width, align=‘center‘,color=‘c‘, label=‘班级A‘, alpha=0.5)
plt.bar(x+bar_width,y1,bar_width, align=‘center‘,color=‘b‘, label=‘班级B‘, alpha=0.5)
plt.xticks(x+bar_width/2, tick_label)
plt.xlabel("测试难度")
plt.ylabel("试卷份数")
plt.legend()
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
x=np.array([1,2,3,4,5])
y=[6,10,4,5,1]
y1=[2,6,3,8,5]
bar_width=0.35
tick_label=[‘A‘,‘B‘,‘C‘,‘D‘,‘E‘]
plt.barh(x, y, bar_width, align=‘center‘,color=‘c‘, label=‘班级A‘, alpha=0.5)
plt.barh(x+bar_width,y1,bar_width, align=‘center‘,color=‘b‘, label=‘班级B‘, alpha=0.5)
plt.yticks(x+bar_width/2, tick_label)
plt.ylabel("测试难度")
plt.xlabel("试卷份数")
plt.legend()
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
x=[1,2,3,4,5]
y=[6,10,4,5,1]
plt.bar(x,y, align=‘center‘, color=‘c‘, tick_label=[‘A‘,‘B‘,‘C‘,‘D‘,‘E‘],
hatch=‘///‘)
plt.xlabel("测试难度")
plt.ylabel("试卷份数")
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
x=np.arange(1,6,1)
y=[0,4,3,5,6]
y1=[1,3,4,2,7]
y2=[1,1,1,1,1]
labels=[‘BluePlanet‘, ‘BrownPlanet‘, ‘GreenPlanet‘]
colors=[‘#8da0cb‘,‘#fc8d62‘,‘#66c2a5‘]
plt.stackplot(x, y, y1, y2, labels=labels, colors=colors)
plt.legend(loc=‘upper left‘)
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
plt.broken_barh([(30,100),(180,50),(260,70)], (20,8), facecolors=‘#1f78b4‘)
plt.broken_barh([(60,90),(190,20),(230,30),(280,60)], (10,8),
facecolors=[‘#7fc97f‘,‘#beaed4‘,‘#fdc086‘,‘#ffff99‘])
plt.xticks(np.arange(0,361,60))
plt.yticks([15,25],[‘歌剧院A‘,‘歌剧院B‘])
plt.xlim(0, 360)
plt.ylim(5, 35)
plt.xlabel("演出时间(分)")
plt.grid(ls=‘-‘, lw=1, color=‘gray‘)
plt.title("不同地区的歌剧院的演出时间比较")
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
x=np.linspace(1,10,10)
y=np.sin(x)
plt.step(x,y,color=‘#8dd3c7‘, where=‘pre‘, lw=2)
plt.xlim(0, 11)
plt.ylim(-1.2, 1.2)
plt.xticks(np.arange(1, 11, 1))
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
x=np.linspace(1,10,10)
y=np.sin(x)
plt.step(x,y,color=‘#8dd3c7‘, where=‘post‘, lw=2)
plt.xlim(0, 11)
plt.ylim(-1.2, 1.2)
plt.xticks(np.arange(1, 11, 1))
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
scoresT=np.random.randint(0,100,100)
x=scoresT
bins=range(0,101,10)
plt.hist(x, bins, color=‘#377eb8‘, histtype=‘bar‘,rwidth=1.0, edgecolor="black")
plt.xlabel("测试成绩")
plt.ylabel("学生人数")
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
scoresT1=np.random.randint(0,100,100)
scoresT2=np.random.randint(0,100,100)
x=[scoresT1,scoresT2]
colors=[‘#8dd3c7‘,‘#bebada‘]
labels=[‘班级A‘,‘班级B‘]
bins=range(0,101,10)
plt.hist(x,bins=bins, color=colors, histtype=‘bar‘, edgecolor="black",
rwidth=1.0, stacked=True, label=labels)
plt.xlabel("测试成绩(分)")
plt.ylabel("学生人数")
plt.title("不同班级的测试成绩直方图")
plt.legend(loc="upper left")
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
scoresT1=np.random.randint(0,100,100)
scoresT2=np.random.randint(0,100,100)
x=[scoresT1,scoresT2]
colors=[‘#8dd3c7‘,‘#bebada‘]
labels=[‘班级A‘,‘班级B‘]
bins=range(0,101,10)
plt.hist(x,bins=bins, color=colors, histtype=‘bar‘, edgecolor="black",
rwidth=0.8, stacked=False, label=labels)
plt.xlabel("测试成绩(分)")
plt.ylabel("学生人数")
plt.title("不同班级的测试成绩直方图")
plt.legend(loc="upper left")
plt.show()
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams[‘font.sans-serif‘]=[‘SimHei‘]
mpl.rcParams[‘axes.unicode_minus‘]=False
scoresT1=np.random.randint(0,100,100)
scoresT2=np.random.randint(0,100,100)
x=[scoresT1,scoresT2]
colors=[‘#8dd3c7‘,‘#bebada‘]
labels=[‘班级A‘,‘班级B‘]
bins=range(0,101,10)
plt.hist(x, bins=bins, color=colors, histtype=‘stepfilled‘, edgecolor="black",
rwidth=1.0, stacked=True, label=labels)
plt.xlabel("测试成绩(分)")
plt.ylabel("学生人数")
plt.title("不同班级的测试成绩的直方图")
plt.legend()
plt.show()
上一篇:python5.2 条件测试
下一篇:分布式系统一致性算法
文章标题:Python数据可视化之matplotlib实践 源码 第一篇 入门 第三章
文章链接:http://soscw.com/index.php/essay/45327.html