2-Animated graphs on one figure HELP

In summary, to plot two animated graphs (y=sin(x) and y=cos(x)) on the same figure, you can use the "plot" function instead of the "comet" function. This will allow both graphs to start at the same time. An example of this is shown in the code above.
  • #1
diiid
2
0
2-Animated graphs on one figure HELP!

I want to plot 2 animated graphs on the same figure (y=sin(x) and y=cos(x)). I wrote this code

x=linspace(0,10,10000);
y1=sin(x);
y2=cos(x);
comet(x,y1);
hold on
comet
hold off

I want that the "comet head" of those two function start at the same time but in the above code i wrote, Only after MATLAB finish my first graph, will it start to plot the second graph. So, can anybody help me to plot those 2 animated graphs starting at the same time on the same figure.

Thank you very much.

My email : nguyentiennhat85@yahoo.com
 
Technology news on Phys.org
  • #2
You can use the "plot" function instead of the "comet" function to plot both animated graphs at the same time. Here is an example of how you could do it:

x=linspace(0,10,10000);
y1=sin(x);
y2=cos(x);
plot(x,y1,'b');
hold on
plot(x,y2,'r');
hold off
 
  • #3


Hello,

Thank you for sharing your code and question. It seems like you are having trouble getting the two animated graphs to start at the same time on the same figure. One potential solution could be to use the "subplot" function in MATLAB. This allows you to create multiple plots on the same figure and control the spacing and layout of the plots.

In your case, you could modify your code to create two subplots, one for the sine function and one for the cosine function. Then, you can use the "comet" function on each subplot separately. This should allow the "comet head" of each function to start at the same time.

Here is an example of how your code could look:

x = linspace(0, 10, 10000);
y1 = sin(x);
y2 = cos(x);

subplot(2,1,1); %create first subplot for sine function
comet(x,y1); %plot sine function on first subplot
title('Sine Function'); %add title to subplot

subplot(2,1,2); %create second subplot for cosine function
comet(x,y2); %plot cosine function on second subplot
title('Cosine Function'); %add title to subplot

I hope this helps and feel free to reach out if you have any further questions.

Best,
 

1. How do I create animated graphs on one figure?

To create animated graphs on one figure, you will need to use a software or programming language that supports animation, such as Python, R, or Tableau. You will also need to have your data organized and formatted correctly before creating the graphs.

2. Can I combine different types of graphs in one figure?

Yes, you can combine different types of graphs, such as bar graphs, line graphs, and scatter plots, in one figure. This can be done by using specialized software or programming techniques, such as subplots or layers.

3. How do I add animation to my graphs?

To add animation to your graphs, you will need to use specific animation functions or modules in your chosen software or programming language. These functions will allow you to specify the type of animation, duration, and other parameters to create the desired effect.

4. Can I control the speed and direction of the animation?

Yes, you can control the speed and direction of the animation in most software or programming languages. This can be done by adjusting the animation parameters, such as duration, frames per second, and direction of movement.

5. How do I export or save the animated graph?

To export or save the animated graph, you will need to use the export or save function in your chosen software or programming language. Most software or languages will allow you to export the graph as a video or GIF file, which can be easily shared or embedded in presentations or reports.

Similar threads

  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
2
Views
856
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
508
  • Programming and Computer Science
Replies
2
Views
1K
  • Calculus and Beyond Homework Help
Replies
10
Views
933
  • Programming and Computer Science
Replies
1
Views
1K
Replies
3
Views
1K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
21
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top