我有一个3x10 2d阵列,我想做一个matplotlib历史绘图。我想要一个子批次中每个数组行的历史图。我试图直接提供ndarray,但发现matplotlib将提供ndarray每列的历史图,这不是我想要的。我怎样才能达到我的目标?目前,我必须为每一行显式地声明hist()
命令,我希望避免这种方法
import numpy as np
import matplotlib.pyplot as plt
d = np.array([[1, 2, 2, 2, 3, 1, 3, 1, 2, 4, 5],
[4, 4, 5, 5, 3, 6, 6, 7, 6, 5, 7],
[5, 6, 7, 7, 8, 8, 9, 10, 11, 12, 10]] )
print( '\nd', d )
fig, ax = plt.subplots(4, 1)
dcount, dbins, dignored = ax[0].hist( d, bins=[2, 4, 6, 8, 10, 12], histtype='bar', label='d' )
d0count, d0bins, d0ignored = ax[1].hist( d[0,:], bins=[2, 4, 6, 8, 10, 12], histtype='bar', label='d0', alpha=0.2 )
d1count, d1bins, d1ignored = ax[2].hist( d[1,:], bins=[2, 4, 6, 8, 10, 12], histtype='bar', label='d1', alpha=0.2 )
d2count, d2bins, d2ignored = ax[3].hist( d[2,:], bins=[2, 4, 6, 8, 10, 12], histtype='bar', label='d2', alpha=0.2 )
ax[0].legend()
ax[1].legend()
ax[2].legend()
ax[3].legend()
print( '\ndcount', dcount )
print( '\ndbins', dbins )
print( '\ndignored', dignored )
print( '\nd0count', d0count )
print( '\nd0bins', d0bins )
print( '\nd0ignored', d0ignored )
print( '\nd1count', d0count )
print( '\nd1bins', d0bins )
print( '\nd1ignored', d0ignored )
print( '\nd2count', d0count )
print( '\nd2bins', d0bins )
print( '\nd2ignored', d0ignored )
plt.show()
我找到了一个更简单的方法。转置
d
。即更换与
我希望matplotlib的
hist()
命令会有一些命令来执行它,但没有找到它。转置numpy数组有效。我想知道这是否是matplotlib用户通常的做法创建要打印的数据
使用list comprehension和^{} :
仅使用一次历史调用打印
导致:
相关问题 更多 >
编程相关推荐