3

I am trying to draw a scatter plot with a point that moves based on a parameter adjusted by a slider. I need the parameter to be the position in a list of the coordinates. I have it so the scatter plot gets drawn and I can manually move the point by change the position, but when I try to implement the slider it is displayed, but can not be drug to update the plot. Any help would be great. What I have so far is below. Thanks.

%pylab from mpl_toolkits.mplot3d import Axes3D from matplotlib import animation def on_change(val): p=int(val)/1 def chart(): x=[0,0.5,1] y=[0,0.5,1] z=[0,0.5,1] p=0 fig = pyplot.figure() ax = fig.add_subplot(111, projection='3d') ax.plot([0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,0],[0,1,1,0,0,0,0,0,1,1,0,0,1,1,1,1],[0,0,1,1,0,0,1,1,1,1,1,0,0,1,0,0],c='black',zorder=10) ax.scatter(x[p],y[p],z[p],zorder=0) ax.set_xlabel('Width') ax.set_ylabel('Depth') ax.set_zlabel('Height') slider_ax = plt.axes([0.15, 0.05, 0.7, 0.02]) slider = Slider(slider_ax, "min", 0, 2, valinit=1, color='blue') pyplot.show() chart() 

1 Answer 1

4

You have to keep a reference to the Slider object around or it (and it's call backs) get garbage collected. See long discussion at https://github.com/matplotlib/matplotlib/issues/3105.

The documentation on this has been clarified for 1.4.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, that helped. Now my issue is that is that when the slider updates the plot, it adds a point to the plot (total of 3 points showing at end) and what I need it to do is have it clear the plot and replot the point at a new position (1 point appears to move from point A to point B. The updated code is above.
If this solved the problem you asked, then please accept this answer and open a new question with your new problem. Answering moving-target questions is very annoying.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.