파이썬에서 matplotlib에 문제가있어 두 개의 플롯을 나란히 만들려고합니다. 나는 그 (것)들을 서로 옆에 머물게 할 수 있었다, 그러나 나는 정확한 크기가 있기 위하여 그 (것)들을 필요로한다 : 우측 것에있는 각 점은 육안을 가진 좌측 것에 위치에 쉽게 매식되어야한다. 대신, 오른쪽 (분산 형 플롯)에는 약간의 여백이있어 왼쪽보다 약간 작게 표시됩니다 (히트 맵).matplotlib : 동일한 크기의 서브 그림?
나는 히트 맵을 생성하는 방법은 다음과 같습니다
def plot_map(matrix):
# Plot it out
#fig, ax = plt.subplots()
fig = plt.figure()
ax = plt.subplot(1,2,1)
c = m.colors.ColorConverter().to_rgb
cm = make_colormap([(0,1,0), (1,1,0), 0.1, (1,1,0), (1,0.5,0), 0.66, (1,0.5,0),(1,0,0)])
heatmap = ax.pcolor(matrix, cmap=cm)
# Format
fig = plt.gcf()
fig.set_size_inches(20, 20)
plt.gca().set_aspect('equal')
# turn off the frame
ax.set_frame_on(False)
# put the major ticks at the middle of each cell
ax.set_yticks(np.arange(matrix.shape[0]) + 0.5, minor=False)
ax.set_xticks(np.arange(matrix.shape[1]) + 0.5, minor=False)
# want a more natural, table-like display
ax.invert_yaxis()
ax.xaxis.tick_top()
# note I could have used matrix.columns but made "labels" instead
ax.set_xticklabels(range(0,matrix.shape[0]), minor=False)
ax.set_yticklabels(range(0,matrix.shape[1]), minor=False)
ax.grid(False)
# Turn off all the ticks
ax = plt.gca()
for t in ax.xaxis.get_major_ticks():
t.tick1On = False
t.tick2On = False
for t in ax.yaxis.get_major_ticks():
t.tick1On = False
t.tick2On = False
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
plt.colorbar(heatmap,cax=cax)
return (fig,ax)
그리고 도끼는지도에 작은 파란색 선 플롯 다른 기능을 통해 전달됩니다
def plot_chosen(edges,endnodes,side,ax):
for e in edges:
u = endnodes[e - 1][0]
v = endnodes[e - 1][1]
xu, yu = get_center(u,side)
xv, yv = get_center(v,side)
ax.plot([xu+0.5, xv+0.5], [yu+0.5, yv+0.5], 'k-', lw=4, color='blue',alpha=0.5)
을 마지막으로, 나는 이처럼 산산조각을 그렸다.
def plot_satter(edges,endnodes,side,xs,ys,data):
plt.margins(0)
ax = plt.subplot(1, 2, 2)
# Format
fig = plt.gcf()
fig.set_size_inches(20, 20)
plt.gca().set_aspect('equal')
# turn off the frame
ax.set_frame_on(False)
# put the major ticks at the middle of each cell
ax.set_yticks(np.arange(side) + 0.5, minor=False)
ax.set_xticks(np.arange(side) + 0.5, minor=False)
# want a more natural, table-like display
ax.invert_yaxis()
ax.xaxis.tick_top()
ax.set_xmargin(0)
ax.set_ymargin(0)
# note I could have used matrix.columns but made "labels" instead
ax.set_xticklabels(range(0,side), minor=False)
ax.set_yticklabels(range(0,side), minor=False)
ax.grid(False)
# Turn off all the ticks
ax = plt.gca()
for t in ax.xaxis.get_major_ticks():
t.tick1On = False
t.tick2On = False
for t in ax.yaxis.get_major_ticks():
t.tick1On = False
t.tick2On = False
cm = make_colormap([(0,0,1), (0,1,1), 0.1, (0,1,1), (1,1,0), 0.66, (1,1,0),(1,0,0)])
resmap = plt.scatter(xs,ys, c=data,cmap=cm,edgecolors='none',alpha=0.5,s=data)
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
plt.colorbar(resmap,cax=cax)
그러나 히트 맵만큼 큰 산점도를 만들 방법이 없습니다. 실제로, 그것은 그것의 컬러 바만큼 클 것이기는하지만 그것도 작동하지 않습니다 ... 이것은 산란계 주변에 여백이 있다고 생각하게합니다 ....
또한, 제가 할 수있는 방법이 있습니까? 전체 PNG 파일을 그렇게 사각형이 아니게 만드시겠습니까? 사각형일까요?
감사합니다!
많은 코드가 있습니다. 가능한 한 멀리 떼어내어 실행 가능하게 만들 수 있습니까? [MCVE] (http://stackoverflow.com/help/mcve) -example? – pathoren