0

my script plots moving trajectories in 3d, with azimuth circling infinitely (simplified example below).

want: control the center/pivot point of the camera/viewer as opposed to having it rotate around the center of the graph space, by default.

ultimate aim: update pivot point at each iteration/frame so camera is always pointing at/rotating around the average location of trajectories.

helpful: how to set "camera position" for 3d plots using python/matplotlib?

def animate2(i):
    ax1.clear()

    for x in smoothed:
        if i<=360:

            ax1.view_init(elev=10., azim=i)
            ax1.plot(data)

        else:
            Az=i-(int(i/360)*360)
            ax1.view_init(elev=10., azim=Az)
            ax1.plot(data)

fig1 = plt.figure()
ax1 = fig1.add_subplot(111, projection='3d')

anim=animation.FuncAnimation(fig1, animate2, interval=8, repeat=True)#frames=range(1, len(test_interp)), 

plt.show()
Community
  • 1
  • 1
user80112
  • 61
  • 1
  • 2
  • 10
  • So where is the problem? Or what is the question? What did you try to achieve your goal and what hinders you in succeeding? – ImportanceOfBeingErnest Dec 02 '16 at 23:12
  • @ImportanceOfBeingErnest I believe the above code is supposed to work, by setting the azimuth/elevation as per the linked question. But the problem is that this only sets the direction of the camera, but not the center of the view point. I'm not sure that can be set at all, matplotlib plots always seem to be inherently centered on the plotting region, at least that's my impression. – Andras Deak -- Слава Україні Dec 02 '16 at 23:20
  • 2
    The title of the question suggests this is something about viewing distance, but the code has no viewing distance in it. If the problem is related to centering the view point as @AndrasDeak suggests, a possible solution might be to shift the plot to center at the desired position instead of setting the camera parameters. – ImportanceOfBeingErnest Dec 03 '16 at 10:31
  • @ImportanceOfBeingErnest good point, I didn't notice that in the title. Definitely unclear, then, you're right. – Andras Deak -- Слава Україні Dec 03 '16 at 10:32
  • thank you-- I have just changed the question title! @AndrasDeak is correct, I am actually curious about setting the viewpoint. The suggestion of shifting the plot/data to be centered instead of setting the camera is a good one, but since I am plotting dynamically moving trajectories, this would cause the plot to resize often throughout the animation (highly unattractive and jarring). – user80112 Dec 04 '16 at 02:15
  • though, I suppose if I remove the lines and tick marks, the resizing/shift in the plot space would be difficult to notice. Not ideal, but a possibility.. – user80112 Dec 04 '16 at 02:17
  • Another option is to do some preprocessing and choose a fixed plot size which you can use throughout. In this case some frames will have smaller, some larger plots in them, but this would actually be equivalent to the "distance" notion you originally asked about. (cc @ImportanceOfBeingErnest ^) – Andras Deak -- Слава Україні Dec 04 '16 at 02:20
  • I think you're suggesting that I use a fixed plot size and let the plot space shift such that the trajectories are always centered? Interesting... Not sure that is the visual we're going for.. – user80112 Dec 04 '16 at 17:55
  • I'm starting to think that maybe setting the camera location in coordinate-space (if that is an option) per frame would be better than using the rotating feature.. – user80112 Dec 04 '16 at 17:56
  • 1
    I'm not closely familiar with these aspects of matplotlib, but my impression is that the camera is always centered on the plot (defined by the given limits), and only the viewing angle can be specified directly. This means that you have to manipulate the plot limits if you want to manipulate the camera focus, and do this in a way that will lead to your intended visual. (Note: if you want me to be notified by a comment, ping me with it) – Andras Deak -- Слава Україні Dec 04 '16 at 19:57
  • I see. Thanks for your help! Out of curiosity, do you know if ggplot or other packages might offer this? @AndrasDeak – user80112 Dec 04 '16 at 23:46
  • actually, if one can control both the azimuth and the distance from the center of the plot.... hmm.. – user80112 Dec 04 '16 at 23:50
  • I"m thinking now that I could find the vector from the center of plot space to the center of the data at each iteration, then offset the camera location by the vector, using distance and altitude.. hmm. will post if I come up with a good solution – user80112 Dec 05 '16 at 00:01

0 Answers0