子批大小python
从图中可以看出我目前面临的问题 左下图上的Y轴非常大,范围从-100到+600。有没有办法修改这个?我试了很多,但都找不到子批大小python,python,matplotlib,subplot,Python,Matplotlib,Subplot,从图中可以看出我目前面临的问题 左下图上的Y轴非常大,范围从-100到+600。有没有办法修改这个?我试了很多,但都找不到 # the random data x = np.random.randint(0,500,100000) y = np.random.randn(100000) fig = plt.figure(1, figsize=(5.5,5.5)) from mpl_toolkits.axes_grid1 import make_ax
# the random data
x = np.random.randint(0,500,100000)
y = np.random.randn(100000)
fig = plt.figure(1, figsize=(5.5,5.5))
from mpl_toolkits.axes_grid1 import make_axes_locatable
# the scatter plot:
axScatter = plt.subplot(111)
axScatter.scatter(x, y)
axScatter.set_aspect(1.)
# create new axes on the right and on the top of the current axes
# The first argument of the new_vertical(new_horizontal) method is
# the height (width) of the axes to be created in inches.
divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)
# make some labels invisible
plt.setp(axHistx.get_xticklabels() + axHisty.get_yticklabels(),
visible=False)
# now determine nice limits by hand:
binwidth = 0.25
print np.max(np.fabs(y))
print np.max(np.fabs(x))
xymax = np.max( [np.max(np.fabs(x)), np.max(np.fabs(y))] )
print xymax #will always be gene length wich should not be
lim = ( int(xymax/binwidth) + 1) * binwidth
print lim
bins = np.arange(0, lim + binwidth, binwidth)
print bins
#two histo grams, should stay of this?
axHistx.hist(x, bins=bins)
axHisty.hist(y, bins=bins, orientation='horizontal')
# the xaxis of axHistx and yaxis of axHisty are shared with axScatter,
# thus there is no need to manually adjust the xlim and ylim of these
# axis.
#axHistx.axis["bottom"].major_ticklabels.set_visible(False)
for tl in axHistx.get_xticklabels():
tl.set_visible(False)
axHistx.set_yticks([0, 50, 100,200])
#axHisty.axis["left"].major_ticklabels.set_visible(False)
for tl in axHisty.get_yticklabels():
tl.set_visible(False)
axHisty.set_xticks([0, 50000, 100000])
plt.draw()
plt.show()
plt.savefig('.png')
现在我可以使用:axScatter.set_ylim(-5,5)
然后收缩轴,但会发生以下情况:
这是一篇重新发布的文章,因为所有被删除的评论…都可以在下面找到一个替代方案,它是您的代码和源代码的混合体。 我想你可以从这一点开始,计算我手动计算的限制:
from matplotlib import pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import numpy as np
x = np.random.randint(0, 500, 100000)
y = np.random.randn(100000)
# definitions for the axes
left, width = 0.1, 0.65
bottom, height = 0.1, 0.65
bottom_h = left_h = left + width + 0.02
rect_scatter = [left, bottom, width, height]
rect_histx = [left, bottom_h, width, 0.2]
rect_histy = [left_h, bottom, 0.2, height]
fig = plt.figure(1, figsize=(5.5,5.5))
axScatter = plt.axes(rect_scatter)
axHistx = plt.axes(rect_histx)
axHisty = plt.axes(rect_histy)
# the scatter plot:
axScatter.scatter(x, y)
binwidth = 0.25
xymax = np.max( [np.max(np.fabs(x)), np.max(np.fabs(y))] )
lim = ( int(xymax/binwidth) + 1) * binwidth
axScatter.set_xlim((0, lim))
axScatter.set_ylim((-5, 10)) # <-- controls y axis. Values should be calculated.
bins = np.arange(-lim, lim + binwidth, binwidth)
axHistx.hist(x, bins=bins)
axHisty.hist(y, bins=bins, orientation='horizontal')
axHistx.set_xlim(axScatter.get_xlim())
axHisty.set_ylim(axScatter.get_ylim())
#axHistx.axis["bottom"].major_ticklabels.set_visible(False)
for tl in axHistx.get_xticklabels():
tl.set_visible(False)
axHistx.set_yticks([0, 50, 200])
#axHisty.axis["left"].major_ticklabels.set_visible(False)
for tl in axHisty.get_yticklabels():
tl.set_visible(False)
axHisty.set_xticks([0, 10000, 20000])
plt.show()
从matplotlib导入pyplot作为plt
从mpl_toolkits.axes_grid1导入使_axes_可定位
将numpy作为np导入
x=np.random.randint(0,500100000)
y=np.random.randn(100000)
#轴的定义
左,宽度=0.1,0.65
底部,高度=0.1,0.65
底部高度=左侧高度=左侧+宽度+0.02
矩形散点=[左、下、宽、高]
rect_histx=[左侧,底部,宽度,0.2]
rect_histy=[左高,底部,0.2,高度]
图=plt.图(1,图尺寸=(5.5,5.5))
轴散射=plt.轴(矩形散射)
axHistx=plt.轴(矩形histx)
axHisty=plt.轴(矩形历史)
#散点图:
axScatter.scatter(x,y)
宽度=0.25
xymax=np.max([np.max(np.fabs(x)),np.max(np.fabs(y)))
lim=(int(xymax/binwidth)+1)*binwidth
axScatter.set_xlim((0,lim))
axScatter.set_ylim(-5,10))#