python绘制马赛克图,每个格⼦填充不同颜⾊
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
import pandas as pd
ax=plt.subplot(111) #注意:⼀般都在ax中设置,不再plot中设置
#x1= np.linspace(0,30, 10)
#x2=np.linspace(60,90, 10)
y1=0
y2=20
y3=740
y4=760
#读取数据
#pemsdata1=
#线圈检测器
for i in range(3):
x1= np.linspace(30*i,30*i+30, 10)
ax.fill_between(x1,y1,y2,facecolor='green')
#
for i in range(6):
x2=np.linspace(30*i,30*i+30, 10)
ax.fill_between(x2,y3,y4,facecolor='red')
#
plt.xlim(0, 900)
plt.ylim(0, 800)
ax.xaxis.set_major_locator(MultipleLocator(30))#设置y主坐标间隔 1
linspace numpyax.yaxis.set_major_locator(MultipleLocator(20))#设置y主坐标间隔 1
id(True,which='major')#major,color='black'
id(True,which='major')#major,color='black'
plt.show()
结果:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。