小编Ham*_*mid的帖子

具有可变线宽的Matplotlib图

是否可以在matplotlib中绘制具有可变线宽的线?例如:

from pylab import *
x = [1, 2, 3, 4, 5]
y = [1, 2, 2, 0, 0]
width = [.5, 1, 1.5, .75, .75]

plot(x, y, linewidth=width)
Run Code Online (Sandbox Code Playgroud)

这不起作用,因为线宽需要标量.

注意:我知道*fill_between()*和*fill_betweenx()*.因为这些只能填充x或y方向,所以这些不适用于有斜线的情况.希望填充总是垂直于线.这就是寻求可变宽度线的原因.

python plot matplotlib

31
推荐指数
2
解决办法
4万
查看次数

混合numpy矩阵和阵列的危险

我正在研究的科学/工程应用有很多线性代数矩阵乘法,因此我使用Numpy矩阵.但是,python中有许多函数可以互换地接受矩阵或数组类型.很好,不是吗?好吧,不是真的.让我用一个例子演示问题:

from scipy.linalg import expm
from numpy import matrix

# Setup input variable as matrix
A = matrix([[ 0, -1.0,  0,  0],
            [ 0,  0,  0,  1.0],
            [ 0,  0,  0,  0],
            [ 0,  0,  1.0,  0]])

# Do some computation with that input
B = expm(A)

b1 = B[0:2, 2:4]
b2 = B[2:4, 2:4].T

# Compute and Print the desired output
print "The innocent but wrong answer:"
print b2 * b1

print "The answer I should get:"
print matrix(b2) …
Run Code Online (Sandbox Code Playgroud)

python arrays numpy matrix

12
推荐指数
2
解决办法
5121
查看次数

标签 统计

python ×2

arrays ×1

matplotlib ×1

matrix ×1

numpy ×1

plot ×1