Effacer les filtres
Effacer les filtres

How to plot overlapping lines while esnuring both remain visible?

96 vues (au cours des 30 derniers jours)
Vivek Bhardwaj
Vivek Bhardwaj le 15 Mai 2018
Commenté : Star Strider le 17 Mai 2018
Hello All, I am having trouble plotting overlapping lines. Consider the code snippet below where I plot the pressure through 5 pipes over 5 time steps. The problem arises when I have two pipes with same pressure and the pressure lines overlap each other. Any help as to how can I best differntiate between them while also ensuring that they are both displayed?
% Code Snippet
t_vect= linspace(1,5,5) % time step vector
P_time = rand(5) %Random pressure values for 5 pipes
P_time(:,2:3) = 0.5; %Assigning same arbitrary values to two pipes (2 and 3)
plot(t_vect,P_time,'--o') % Plotting the pressure in 5 pipes against t_vect
And as you can see in the picture there is no way one can distinguish between pressures in pipes 2 and 3. But here comes my major concern, the number of pipes in my case are not constant and neither are the number of pipes with same pressure values (possibility of more than 2 lines overlapping), so is there a way this could be automated?
  2 commentaires
KALYAN ACHARJYA
KALYAN ACHARJYA le 15 Mai 2018
Which two lines you are talking about?
Vivek Bhardwaj
Vivek Bhardwaj le 15 Mai 2018
Hi, I have added a legend so that it becomes more apparent. The straight yellow line in the middle is the pressure reading for Pipe 3 which completely overlaps the pressure for pipe 2 (marked as red in legend), since they were assigned the same values (0.5). What I want is that the two lines should be distinguishable.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 15 Mai 2018
I would plot ‘pipe 3’ (or whatever one is plotted later) with a larger line width, or plot ‘pipe 2’ (if plotted first) as a solid line.
  4 commentaires
Vivek Bhardwaj
Vivek Bhardwaj le 17 Mai 2018
Thank you. The lines are distinguishable, I'll play around a bit and see what works best.
Star Strider
Star Strider le 17 Mai 2018
As always, my pleasure.

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 15 Mai 2018
% The actual data:
t = 0:5;
x1 = zeros(size(t));
x2 = zeros(size(t));
tt = linspace(0, 5, 20);
x1t = interp1(t, x1, tt);
x2t = interp1(t, x2, tt);
plot(tt, x1t, '--o', 'MarkerIndices', 1:5:length(tt));
plot(tt, x2t, '--o', 'MarkerIndices', 3:5:length(tt));
Well, I'm not convinced that this is nice. It is not trivial to do this automatically using an optimal distance between the markers of overlapping lines. But you have at least a method, to detect such identical curves.
  2 commentaires
Vivek Bhardwaj
Vivek Bhardwaj le 17 Mai 2018
Thank you for the reply. Managing where the markers are displayed does seem to be a feasible way but I think the property 'MarkerIndices' is only available for the new releases as I have R2016a and I get an error when I use the 'MarkerIndices' property.
Error: "Error using plot There is no MarkerIndices property on the Line class."

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by