我正在使用matplotlib生成3D图.我希望能够放大感兴趣的领域.目前,我能够平移但不能缩放.看一下mplot3d API,我了解了一下can_pan():
Return True if this axes supports the pan/zoom button functionality.
3D axes objects do not use the pan/zoom button.
Run Code Online (Sandbox Code Playgroud)
和 can_zoom():
Return True if this axes supports the zoom box button functionality.
3D axes objects do not use the zoom box button.
Run Code Online (Sandbox Code Playgroud)
它们都返回False(我认为can_pan返回False,因为轴不能平移和缩放两者但是我可能正在读错API).
有没有办法启用Zoom?API表示它不使用按钮.有没有办法启用缩放或设置它can_pan()并can_zoom()返回True?
以下是代码片段:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
data = np.genfromtxt('data_file.txt')
fig1 = plt.figure()
ax1 = fig1.gca(projection='3d')
ax1.scatter(data[:,0],data[:,1],data[:,2], c='r', marker='.')
plt.show()
ax1.can_zoom() …Run Code Online (Sandbox Code Playgroud) 我很难过.我编写的日期清理功能在我的Mac上使用Python 2.7.5,但在我的Ubuntu服务器上不在2.7.6中.
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> date = datetime.strptime('2013-08-15 10:23:05 PDT', '%Y-%m-%d %H:%M:%S %Z')
>>> print(date)
2013-08-15 10:23:05
Run Code Online (Sandbox Code Playgroud)
为什么这在Ubuntu的2.7.6中不起作用?
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> date = datetime.strptime('2013-08-15 10:23:05 PDT', '%Y-%m-%d %H:%M:%S %Z') …Run Code Online (Sandbox Code Playgroud) >>> a = np.arange(9).reshape((3, 3))
>>> a
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> def sub(a):
... return a[:2, :2]
...
>>> sub(a)
array([[0, 1],
[3, 4]])
>>> sub(a) = np.arange(4).reshape((2, 2))
File "<stdin>", line 1
SyntaxError: cant assign to function call
>>> t = a[:2, :2]
>>> t = np.arange(4).reshape((2, 2))
>>> a
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>> a[:2, :2] = np.arange(4).reshape((2, 2))
>>> a
array([[0, 1, 2],
[2, 3, 5], …Run Code Online (Sandbox Code Playgroud) 我需要在python中执行以下操作.我有一个字符串列表list,一个要搜索的字符串text,以及包含要打印的元素数量的变量x.我想迭代一下x.连续的元素,必要时list包裹在前面list.
首先,我需要找到的第一个元素中list有text一个子.然后我将从匹配元素list 之后的第一个元素开始,并继续遍历整个x连续元素,list必要时包裹.
我该怎么做?
x = 11
text = "string5"
list = ["string1", "string2", "string3", "string4", "string5", "string6", "string7"]
# not sure what to do here...
for elem in list:
if text in elem:
#iterate through list, begin with elem and get the next 11 elements
#once you've reached string7, start over with string1`
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我想最终看看以下11个元素:
string6
string7
string1 …Run Code Online (Sandbox Code Playgroud) 我已经看到很多问题要求以更快的方式迭代2d数组的每个元素,但是我没有找到一个很好的方法迭代3d数组以便在每个2d数组上应用函数.例如:
from scipy.fftpack import dct
X = np.arange(10000, dtype=np.float32).reshape(-1,4,4)
np.array(map(dct, X))
Run Code Online (Sandbox Code Playgroud)
在这里,我将浏览包含在3d维数组中的每个2d数组,(625,4,4)并对每个4X4数组应用DCT(离散余弦变换).我想知道是否有更合适的方法来实现这一目标.
谢谢
我想设置numpy数组的值如下.但我不想用for-loop.有什么好办法吗?
a = range(4)
a[0] = [11,12,13,14,15,16]
a[1] = [21,22,23,24,25,26]
a[2] = [31,32,33,34,35,36]
a[3] = [41,42,43,44,45,46]
a = np.array(a)
changeIndex = [0,2,4]
for i in range(4):
a[i][changeIndex] = 0
print a
#array([[ 0, 12, 0, 14, 0, 16],
# [ 0, 22, 0, 24, 0, 26],
# [ 0, 32, 0, 34, 0, 36],
# [ 0, 42, 0, 44, 0, 46]])
Run Code Online (Sandbox Code Playgroud)