0

I want to plot a series of lines, with each line being colored according to a certain weight. I stumbled accross this, but the problem is, I am plotting multiple things on one graph, where only one of the plot statements should be color weighted.

I'm using hold on; hold off;, but I only see the last graph. Thus, the final result is, I only see the color weighted plot statements, but not the other plot statements that should be plotted due to hold on; hold off;.

Here is my code, where upper*p is an n x 1 vector representing the intensity of each of the n lines:

cmap = colormap;
con_min = min(upper*p)*25;
con_max = max(upper*p)*25;
ind_upper = ceil((size(cmap,1)-1)*((con_min:con_max)'-con_min+1)/(con_max-con_min));

subplot(2,3,2);
hold on;
    title('Gains');
    set(gca,'ColorOrder',cmap(ind_upper,:),'NextPlot','replacechildren');
    plot(flat','c');
    plot(lower','c');
    plot(upper');
    set(gca, 'xtick',1:labelFreq:num_tickers, 'xticklabel', tickers(1:4:num_tickers));
    ylabel('bp change on day');
    colorbar;
    caxis([con_min con_max]);
hold off;

It seems the "upper" part is plotted correctly according to the color weights, but the "flat" and "lower" graphs do not show. I think it's because the set(gca,...) statement is causing the graphs to reset.

double-beep
  • 5,031
  • 17
  • 33
  • 41
user3685285
  • 6,066
  • 13
  • 54
  • 95
  • Can you actually show us the code you're talking about? If you call `hold off`, the next plot will clear everything – Suever Sep 27 '16 at 15:04
  • Sorry, just added the code. – user3685285 Sep 27 '16 at 15:09
  • 1
    Why do you set the `NextPlot` to `'replaceChildren'`? You know that's the same as calling `hold off` right? – Suever Sep 27 '16 at 15:38
  • 1
    I believe @Suever is recommending that you replace `set(gca,'ColorOrder',cmap(ind_upper,:),'NextPlot','replacechildren');` with `set(gca,'ColorOrder',cmap(ind_upper,:));` – Trogdor Sep 27 '16 at 17:35
  • `flat` and `lower` are getting potted with the "cyan" color. Is that what you intended? – John Sep 27 '16 at 18:08
  • It would be more helpful if you gave a complete example, demonstrating your problem. I can't run your code above, and have it generating anything. So, I am having a hard time understanding what you are expecting to see, vs. what you are seeing. If you think the set(gca... commands are problematic, remove them, and see if it helps.... – John Sep 27 '16 at 18:09

0 Answers0