matplotlib 3D绘图与不断变化的标签 [英] matplotlib 3d plot with changing labels
问题描述
所以我有一个3D实时更新的图形!这只能说明一点的时间,所以我可以很容易地跟踪点的运动!但现在的问题是:
So I have a 3d live-updating graph! it only shows one point at a time so I can easily track the motion of the point! But here is the problem:
无论我似乎做,点始终放在图表和轴变化的刻度线的中心,为了做到这一点。这使我的生活非常困难,因为我看不到的点的运动。这是我的code:
No matter what I seem to do, the point is always placed in the center of the graph and the tick marks on the axis change in order to do that. This makes my life very difficult because I don't see the motion on the point. Here is my code:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from pylab import *
import time
import pandas as pd
import pickle
def pickleLoad(pickleFile):
pkl_file = open(pickleFile, 'rb')
data = pickle.load(pkl_file)
pkl_file.close()
return data
data = pickleLoad('/Users/ryansaxe/Desktop/kaggle_parkinsons/accelerometry/LILY_dataframe')
data = data.reset_index(drop=True)
df = data.ix[0:,['x.mean','y.mean','z.mean','time']]
ion()
fig = figure()
ax = fig.add_subplot(111, projection='3d')
count = 0
plotting = True
labels = range(-10,11)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
ax.set_yticklabels(labels)
ax.set_xticklabels(labels)
ax.set_zticklabels(labels)
lin = None
while plotting:
df2 = df.ix[count]
count += 1
xs = df2['x.mean']
ys = df2['y.mean']
zs = df2['z.mean']
t = df2['time']
ax.set_title(t)
if lin is not None:
lin.remove()
lin = ax.scatter(xs, ys, zs)
draw()
pause(0.01)
if count > 100:
plotting = False
ioff()
show()
这里是数据的示例:
here is an example of the data:
x.mean y.mean z.mean time
0 -1.982905 3.395062 8.558263 2012-01-18 14:00:03
1 0.025276 -0.399172 7.404849 2012-01-18 14:00:04
2 -0.156906 -8.875595 1.925565 2012-01-18 14:00:05
3 2.643088 -8.307801 2.382624 2012-01-18 14:00:06
4 3.562265 -7.875230 2.312898 2012-01-18 14:00:07
5 4.441432 -7.907592 2.851774 2012-01-18 14:00:08
6 4.124187 -7.854146 2.727229 2012-01-18 14:00:09
7 4.199698 -8.135596 2.677706 2012-01-18 14:00:10
8 4.407856 -8.133449 2.214902 2012-01-18 14:00:11
9 4.096238 -8.453822 1.359692 2012-01-18 14:00:12
所以,我能做些什么来让这个刻度线是固定的所以点移动,而不是刻度线的变化?
推荐答案
这是 Axes3D
对象(你的斧
变量)有以下方法: set_xlim
, set_ylim
和 set_zlim
。你可以用它们来修复您的轴的限制。
An Axes3D
object (your ax
variable) has the following methods: set_xlim
, set_ylim
, and set_zlim
. You could use these to fix the limits of your axes.
文件:
- <一个href="http://matplotlib.org/mpl_toolkits/mplot3d/api.html?highlight=axes3d#mpl_toolkits.mplot3d.axes3d.Axes3D.set_xlim"相对=nofollow> set_xlim
- <一个href="http://matplotlib.org/mpl_toolkits/mplot3d/api.html?highlight=axes3d#mpl_toolkits.mplot3d.axes3d.Axes3D.set_xlim3d"相对=nofollow> set_xlim3d
- set_xlim
- set_xlim3d
修改
使用 set_xlim
等,对我的作品。这是我的code:
Using set_xlim
, etc, works for me. Here is my code:
#!python2
from mpl_toolkits.mplot3d import Axes3D
from pylab import *
data = [
[-1.982905, 3.395062, 8.558263, '2012-01-18 14:00:03'],
[ 0.025276, -0.399172, 7.404849, '2012-01-18 14:00:04'],
[-0.156906, -8.875595, 1.925565, '2012-01-18 14:00:05'],
[ 2.643088, -8.307801, 2.382624, '2012-01-18 14:00:06'],
[3.562265, -7.875230, 2.312898, '2012-01-18 14:00:07'],
[4.441432, -7.907592, 2.851774, '2012-01-18 14:00:08'],
[4.124187, -7.854146, 2.727229, '2012-01-18 14:00:09'],
[4.199698, -8.135596, 2.677706, '2012-01-18 14:00:10'],
[4.407856, -8.133449, 2.214902, '2012-01-18 14:00:11'],
[4.096238, -8.453822, 1.359692, '2012-01-18 14:00:12'],
]
ion()
fig = figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
ax.set_xlim((-10, 11))
ax.set_ylim((-10, 11))
ax.set_zlim((-10, 11))
lin = None
for x, y, z, t in data:
ax.set_title(t)
if lin is not None:
lin.remove()
lin = ax.scatter(x, y, z)
draw()
pause(0.1)
ioff()
show()
编辑2
您可以看看关闭轴自动缩放,这是默认。也许这是覆盖 set_lim
的方法。
You could have a look at switching off autoscaling of axes which is on by default. Maybe this is overriding the set_lim
methods.
文件:
- <一个href="http://matplotlib.org/mpl_toolkits/mplot3d/api.html?highlight=axes3d#mpl_toolkits.mplot3d.axes3d.Axes3D.autoscale"相对=nofollow>自动缩放
- <一个href="http://matplotlib.org/mpl_toolkits/mplot3d/api.html?highlight=axes3d#mpl_toolkits.mplot3d.axes3d.Axes3D.autoscale_view"相对=nofollow> autoscale_view
- autoscale
- autoscale_view
这篇关于matplotlib 3D绘图与不断变化的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!