如何在python中生成真值的水平图
我希望通过绘制一个图表来比较三个真值列表 例如,我有三个很长的布尔值列表(True和False)如何在python中生成真值的水平图,python,matplotlib,Python,Matplotlib,我希望通过绘制一个图表来比较三个真值列表 例如,我有三个很长的布尔值列表(True和False) list1 = [True,False,True,True,True,False...] 有人能告诉我最简单的方法来制作一个图形,如果它是真的,它会标记为红色,如果它是假的,它会标记为白色或黑色 def morse(lists): for i,list_ in enumerate(lists): for j,value in enumerate(list_):
list1 = [True,False,True,True,True,False...]
有人能告诉我最简单的方法来制作一个图形,如果它是真的,它会标记为红色,如果它是假的,它会标记为白色或黑色
def morse(lists):
for i,list_ in enumerate(lists):
for j,value in enumerate(list_):
if value:
plt.plot([j,j+1],[i,i],'r',linewidth=5.0)
plt.axis([0,j+1,-1,i+1])
labels=['List'+str(i) for i in range(1,len(lists)+1)]
plt.tick_params(
axis='x', # changes apply to the x-axis
which='both', # both major and minor ticks are affected
bottom='off', # ticks along the bottom edge are off
top='off', # ticks along the top edge are off
labelbottom='off'
)
plt.tick_params(
axis='y', # changes apply to the y-axis
which='minor', # minor ticks are affected
left='off', # ticks along the left edge are off
right='off' # ticks along the right edge are off
)
plt.xlabel('index')
plt.yticks(range(len(lists)),labels)
plt.show()
import matplotlib.pyplot as plt
morse([[True,False,True],[False,False,True]])
非常感谢您。请您更新代码,将列表的索引添加到横轴上。例如0,1,2,3,4,5,6只需添加
plt.xticks(范围(len(列表[0]))
,并在x轴上用which='minor'
更改which='bother'
,列表太大(1000个索引)。如何在这些刻度中显示间隔?(每百分之一指数)?很抱歉为这么简单的任务打扰你。我意识到这可以通过使用plt.xticks(范围(0,len(列表[0]),100))来实现