How do I manually set color of individual datapoints of figure ?
댓글 수: 0
답변 (3개)
댓글 수: 3
Hi @Jad,
To address the issue of color-coding individual curves in a shuffled matrix, you can manually specify the indices of the points that belong to each curve. This approach allows you to plot each curve with a distinct color, even when the data is not organized in a conventional manner. I took liberty to refine @Strider’s code, Hope he does not mind to help you out.
cm = turbo(5); % Define a colormap with 5 colors Fs = 1000; t = linspace(0, 301, 302).'/Fs;
% Example shuffled data E = [sin(2*pi*t*1), sin(2*pi*t*5), sin(2*pi*t*10), sin(2*pi*t*15), sin(2*pi*t*20)];
figure hold on
% Manually specify the indices for each curve curveIndices = {1:100, 101:200, 201:302}; % Adjust these ranges based on your data
for k = 1:length(curveIndices) plot(t(curveIndices{k}), E(curveIndices{k}, k), 'Color', cm(k,:), 'DisplayName', ["Curve " + k]); end
hold off legend('Location', 'best')
Please see attached.
In this refined code, curveIndices is an array of ranges that specify which points belong to each curve. Adjust these indices according to your specific data structure. This method provides clarity and control over the visualization of your curves. Hope this should help resolve your problem.
Hi @Jad,
You asked, “I don't want to go through the trouble of doing some sort of data-analysis / fitting to figure out which data-point belongs to which curve. I don't mind coloring the points myslef since I only need to produce a few of these figures. I tried using the brush to paint points one color but I can't manage to get multiple brush colors. How can I manually paint these points ?”
Please see my response to your comments below.
Your original approach involves plotting the matrix using a scatter plot, but due to the random order of values, you are experiencing issues with color consistency. Also, you want to manually assign colors to each curve without resorting to data fitting or complex analysis. Here's an updated MATLAB code snippet that accomplishes this:
% Sample matrix E (5x302) E = rand(5, 302); % Replace this with your actual data
% Define colors for each curve colors = {'r', 'g', 'b', 'm', 'c'}; % Red, Green, Blue, Magenta, Cyan
% Create a figure figure; hold on;
% Loop through each curve for m = 1:5 % Extract the current curve's values and plot them % Here we use a scatter plot with specific colors scatter(1:302, sqrt(abs(real(E(m,:)))), 36, colors{m}, 'filled'); end
% Add labels and title for clarity xlabel('X-axis'); ylabel('Y-axis'); title('Colored Curves'); legend({'Curve 1', 'Curve 2', 'Curve 3', 'Curve 4', 'Curve 5'}, 'Location', 'Best'); hold off;
So, in the above code, I have initialized E as a random matrix for demonstration purposes. Replace it with your actual data. Also, a cell array named colors is created to hold the desired colors for each curve. You can expand or modify the colors array if you wish to use different color schemes. A figure is created and hold on allows multiple plots on the same figure. The loop iterates over each curve index m from 1 to 5 and the scatter function is used to plot each curve's values with its corresponding color. The third parameter (36) specifies the marker size. Adjust the marker size (currently set at 36) based on your visual preferences or data density. Using sqrt(abs(real(E(m,:)))) makes sure that you're applying your transformation consistently across all curves. Make sure that your matrix E contains valid numerical data before plotting.
Please see attached.
Please let me know if you have any further questions.
댓글 수: 0
댓글 수: 0
참고 항목
카테고리
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!