有没有将matlab .mat(matlab格式化数据)文件转换为Panda 的标准方法DataFrame?
我知道通过使用可以解决方法,scipy.io但我想知道是否有一种直接的方法来做到这一点.
所以我有以下示例绘制图形和插图:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
x = np.arange(100).reshape((10, 10))
ax1.imshow(x)
ax2 = fig.add_axes([0.5, 0.5, 0.3, 0.3])
t = np.arange(0, 1, 0.01)
s = np.sin(t)
ax2.plot(t, s, linewidth=2)
Run Code Online (Sandbox Code Playgroud)
我想要的是插图有点透明(比如alpha = 0.5).我想要他们在matplotlib文档中的图例文档中所做的事情:
http://matplotlib.org/users/recipes.html#transparent-fancy-legends
那可能吗?有谁知道这是怎么做到的吗?
祝一切顺利,
PD正如评论中所提到的,这个问题的答案可以从对相关问题的答案中得出.它在概念上有点不同(图与轴),在这里IMO要简单得多.
所以这是关于重塑的使用以及该函数如何在多维尺度上使用每个轴的问题.
假设我有以下数组,其中包含由第一个索引索引的矩阵.我想要实现的是用第一个索引来索引每个矩阵的列.为了说明此问题,请考虑以下示例,其中使用其第一个索引对矩阵进行索引的给定numpy数组为z.
x = np.arange(9).reshape((3, 3))
y = np.arange(9, 18).reshape((3, 3))
z = np.dstack((x, y)).T
Run Code Online (Sandbox Code Playgroud)
z看起来像:
array([[[ 0, 3, 6],
[ 1, 4, 7],
[ 2, 5, 8]],
[[ 9, 12, 15],
[10, 13, 16],
[11, 14, 17]]])
Run Code Online (Sandbox Code Playgroud)
它的形状是(2, 3, 3).这里,第一个索引是两个图像,三个x三个是矩阵.
那时更具体的措辞是如何使用重塑来获得以下所需的输出:
array([[ 0, 1, 2],
[ 3, 4, 5],
[ 6, 7, 8],
[ 9, 10, 11],
[12, 13, 14],
[15, 16, 17]])
Run Code Online (Sandbox Code Playgroud)
谁的形状(6, 3).这实现了阵列的尺寸索引矩阵x和y的列,如上所述.我的自然倾向是通过以下方式 …
下面的代码连续显示并保存随机矩阵的动画.我的问题是如何调整我保存的动画的持续时间.这里我唯一的参数是fps,dpi控制帧剩余的秒数,第二个控制图像的质量.我想要的是实际控制将根据矩阵实际存储的数量保存的帧数.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
N = 5
A = np.random.rand(N,N)
im = plt.imshow(A)
def updatefig(*args):
im.set_array(np.random.rand(N,N))
return im,
ani = animation.FuncAnimation(fig, updatefig, interval=200, blit=True)
ani.save('try_animation.mp4', fps=10, dpi=80) #Frame per second controls speed, dpi controls the quality
plt.show()
Run Code Online (Sandbox Code Playgroud)
我很想知道是否应该添加更多参数.我试图在matplotlib的类文档中寻找合适的一个但是我没有成功:
http://matplotlib.org/api/animation_api.html#module-matplotlib.animation