小编Pet*_*fin的帖子

更改matplotlib中子图的纵横比

我已经创建了一系列简单的灰度图像,我已经在网格中绘制(遗憾的是,由于我没有足够高的声誉,所以无法上传图像:().

伪代码是

# Define matplotlib PyPlot object

nrow =  8
ncol = 12

fig, axes = plt.subplots(nrow, ncol, subplot_kw={'xticks': [], 'yticks': []})
fig.subplots_adjust(hspace=0.05, wspace=0.05)

# Sample the fine scale model at random well locations

for ax in axes.flat:

    plot_data = # some Python code here to create 2D grey scale array...

    # ... create sub-plot

    img = ax.imshow(plot_data, interpolation='none')
    img.set_cmap('gray')

# Display the plot

plt.show()        
Run Code Online (Sandbox Code Playgroud)

我想改变纵横比,以便绘图垂直压扁并水平拉伸.我尝试过使用ax.set_aspect并将'aspect'作为subplot_kw参数传递,但无济于事.我也关闭了'autoscale',但我只能看到一些像素.欢迎所有建议!

提前致谢!!

@JoeKington - 谢谢!那是一个很棒的回复!! 仍然试图让我全神贯注.还要感谢其他海报的建议.因此,原始情节看起来像这样:http://imgur.com/Wi6v4cs 当我设置'aspect ='auto'时,情节看起来像这样:http://imgur.com/eRBO6MZ 这是一个很大的改进.我现在需要做的就是调整子图大小,以便以2:1的纵向纵横比绘制子图,但是图中填充整个子图.我想'colspan'会这样做吗?

python matplotlib

7
推荐指数
1
解决办法
1万
查看次数

可以用 scipy minimize 拟合曲线,但不能用 scipy curve_fit 拟合曲线

我正在尝试使用该函数y= 1-a(1-bx)**n来拟合一些实验数据scipy curve_fit。该模型仅在 y>0 时存在,因此我剪裁计算值以强制执行此操作。代码如下所示

import numpy as np
import scipy.optimize
import matplotlib.pyplot as plt

# Driver function for scipy.minimize

def driver_func(x, xobs, yobs):

    # Evaluate the fit function with the current parameter estimates

    ynew = myfunc(xobs, *x)
    yerr = np.sum((ynew - yobs) ** 2)

    return yerr

# Define function

def myfunc(x, a, b, n):

    y = 1.0 - a * np.power(1.0 - b * x, n) 
    y = np.clip(y, 0.00, None )

    return y

if …
Run Code Online (Sandbox Code Playgroud)

curve-fitting python-3.x scipy-optimize

5
推荐指数
1
解决办法
4413
查看次数