matplotlib에서 두 가지 다른 그림이 있습니다. 첫 번째는 시간에 따른 셀 크기를 보여줍니다.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import mahotas
import random
fig,ax_curves = plt.subplots(figsize=(8,6))
for cell in range(1,11):
ax_curves.set_ylim(0,100)
ax_curves.set_xlim(0,25)
ax_curves.set_xticks(np.arange(0,21))
ax_curves.plot(np.arange(0,21), random.sample(range(40, 61), 21), label = str(cell))
ax_curves.legend(loc='right',frameon=False)
ax_curves.spines['right'].set_visible(False)
ax_curves.spines['top'].set_visible(False)
ax_curves.set_title('Curves')
plt.show()
두 번째는 서로 다른 시점에서 이러한 세포의 이미지를 보여줍니다.
fig, ax_images =plt.subplots(10,5,figsize=(9, 16))
columns = 5
rows = 10
for column in range(0, columns):
cell = 1
for row in range(0,rows):
ax_images[row, column].axes.get_xaxis().set_visible(False)
ax_images[row, column].tick_params(
axis='y',
which='both',
left=False,
right=False,
labelleft=False)
ax_images[row, 0].set_ylabel('Cell ' + str(cell), rotation = 0, color=tab10.colors[row])
ax_images[row, 0].yaxis.set_label_coords(-0.4,0.5)
if column == 0:
plt.figtext(0.14 , 0.9, '0 hour',fontsize = 20)
img = mahotas.imread('path/to/image_t0.tif')
if column == 1:
plt.figtext(0.28, 0.9, '5 hours',fontsize = 20)
img = mahotas.imread('path/to/image_t5.tif')
if column == 2:
plt.figtext(0.44 , 0.9, '10 hours', fontsize = 20)
img = mahotas.imread('path/to/image_t10.tif')
if column == 3:
plt.figtext(0.60, 0.9, '15 hours',fontsize = 20)
img = mahotas.imread('path/to/image_t15.tif')
if column == 4:
plt.figtext(0.76 , 0.9, '20 hours', fontsize = 20)
img = mahotas.imread('path/to/image_t20.tif')
ax_images[row, column].imshow(img)
cell = cell + 1
plt.figtext(0.5,0.95,'Cell size through time', fontsize = 20, horizontalalignment='center')
plt.show()
이 두 그림을 "수집"하고 싶습니다 (첫 번째는 왼쪽에 있고 두 번째는 오른쪽에있는 예). 나는 여러 시간 동안 시도 GrisSpec
하거나 add_subplot
하지만, 당신은 당신이이 문제를 해결하는 단서가 있다면 알려 주시기 바랍니다 수 ... 실패?
친절하게 당신!
@gboffi의 답변 덕분에 내 문제를 해결할 수있었습니다.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import mahotas
import random
f = plt.figure(figsize=(13,4))
ax_curves = f.add_axes((0.10,1.5, 0.33, 0.85))
for cell in range(1,11):
ax_curves.set_ylim(0,100)
ax_curves.set_xlim(0,30)
ax_curves.set_xticks(np.arange(0,21,5))
ax_curves.plot(np.arange(0,21), random.sample(range(40, 61), 21), label = 'Cell ' + str(cell))
ax_curves.legend(loc='right',frameon=False)
ax_curves.spines['right'].set_visible(False)
ax_curves.spines['top'].set_visible(False)
ax_curves.set_title('Curves')
for column in np.linspace(0.5, 0.9, 5):
cell = 1
tab10 = matplotlib.cm.get_cmap('tab10')
for row in np.linspace(2.8, 0.10, 10):
# LL corner, width, height in figure coordinates, 0 ≤ x,y,h,w ≤ 1
ax_images = f.add_axes((column, row, 0.09, 0.27))
ax_images.axes.get_xaxis().set_visible(False)
ax_images.tick_params(
axis='y',
which='both',
left=False,
right=False,
labelleft=False)
if column == 0.5:
ax_images.set_ylabel('Cell ' + str(cell), rotation = 0, color=tab10.colors[cell-1])
ax_images.yaxis.set_label_coords(-0.4,0.5)
else :
pass
if column == 0.5:
plt.figtext(column+0.01 , 3.1, '0 hour',fontsize = 20)
# img = mahotas.imread('path/to/image_t0.tif')
if column == 0.6:
plt.figtext(column, 3.1, '5 hours',fontsize = 20)
# img = mahotas.imread('path/to/image_t5.tif')
if column == 0.7:
plt.figtext(column , 3.1, '10 hours', fontsize = 20)
# img = mahotas.imread('path/to/image_t10.tif')
if column == 0.8:
plt.figtext(column, 3.1, '15 hours',fontsize = 20)
# img = mahotas.imread('path/to/image_t15.tif')
if column == 0.9:
plt.figtext(column , 3.1, '20 hours', fontsize = 20)
# img = mahotas.imread('path/to/image_t20.tif')
# ax[row, column].imshow(img)
cell = cell + 1
plt.figtext(0.5,3.33,'Cell sizes through time', fontsize = 20, horizontalalignment='center')
당신의 도움을 주셔서 대단히 감사합니다 !!!
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다