How to avoid overlapping when plotting in for loop
Mostrar comentarios más antiguos

t=[ %to print text
text(2,3.5,'')
text(2,3,'')
text(2,2.5,'')
text(2,2,'')
text(2,1.5,'')
];
for i = 200:10:2700
% Forward kinematics
th1 = simOut.ScopeData.signals.values(i,1);
th2 = simOut.ScopeData.signals.values(i,2);
th3 = simOut.ScopeData.signals.values(i,3);
x1 = L1*cos(th1);
y1 = L1*sin(th1);
x2 = L2*cos(th1 + th2) + x1;
y2 = L2*sin(th1 + th2) + y1;
x3 = L3*cos(th1 + th2 + th3) + x2;
y3 = L3*sin(th1 + th2 + th3) + y2;
set(t(1),'String',sprintf('X : %.2f',x3));
set(t(2),'String',sprintf('Y : %.2f',y3));
set(t(3),'String',sprintf('joint 1 angle : %.2f',th1*180/pi));
set(t(4),'String',sprintf('joint 2 angle : %.2f',th2*180/pi));
set(t(5),'String',sprintf('joint 3 angle : %.2f',th3*180/pi)); % I want to plot without removing the text.
hold on
plot(x1, y1, 'ok', 'Linewidth', 2) % joint 1
plot(x2, y2, 'ok', 'Linewidth', 2) % joint 2
plot(x3, y3, 'ok', 'Linewidth', 2) % joint 3
plot([ox, x1],[oy, y1], 'r', 'Linewidth', 2) % link 1
plot([x1, x2],[y1, y2], 'b', 'Linewidth', 2) % link 2
plot([x2, x3],[y2, y3], 'g', 'Linewidth', 2) % link 3
hold off
max_L = L1+L2+1;
axis([-max_L max_L -max_L max_L])
grid on
2 comentarios
Jan
el 29 de Mayo de 2022
What do you call "overlapping" in this picture?
Image Analyst
el 29 de Mayo de 2022
Attach your data with the paperclip icon after you read this:
save('answers.mat', 'simOut');
Also show us a plot of what you'd like the output plot to look like.
Respuestas (1)
Muhammad Majid
el 29 de Mayo de 2022
1 voto
def plotStats(aggr_ep_rewards, i, my_file):
'''Plot rewards curves'''
DIR = '../Simulations/2_Q_Learning_exploration_explotation/A/'
plt.plot(aggr_ep_rewards['ep'], aggr_ep_rewards['avg'])#label="average rewards"
plt.legend(loc=4)
plt.title(f"RL Q_Learning TEST:{i}")
plt.xlabel('Episodes')
plt.ylabel('Rewards')
# plt.show()
plt.savefig(os.path.join(DIR, my_file))
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!