Hi @ NAFISA SIDDIQUI,
If I comprehend your instructions by looking at the Cartesian coordinate graph displaying all four quadrants on x and y axis. Then, please see modified updated codes below. You can customize the codes based on your preferences.
So, in the first modified code which shows both comparison and centered data on the same plot. The first part of the code remains the same while the visualization part is modified. So, in the visualization step, it creates a scatter plot for both the raw and centered data, using blue and red markers, respectively. The plot is further enhanced with titles, axis labels, and a legend for clarity. Additionally, the axis limits are set so that both datasets are visible, and the axes are positioned at the origin for better interpretation. Finally, a grid is added to the plot, improving the overall readability. Here is first updated code below.
Updated Code#1
% Step 1: Define the raw data WireLength = [1, 4, 5, 6, 8, 10, 12, 14, 13, 18, 19, 22]; DieHeight = [125, 110, 287, 200, 350, 280, 400, 370, 480, 420, 540, 518];
% Step 2: Center the data meanWireLength = mean(WireLength); meanDieHeight = mean(DieHeight);
centeredWireLength = WireLength - meanWireLength; centeredDieHeight = DieHeight - meanDieHeight;
% Step 3: Create the scatter plots figure; % Create a new figure window
% Plot raw data scatter(WireLength, DieHeight, 'filled', 'MarkerFaceColor', 'b'); hold on; % Hold on to the current plot
% Plot centered data scatter(centeredWireLength, centeredDieHeight, 'filled', 'MarkerFaceColor', 'r');
% Step 4: Customize the plot title('Raw Data and Centered Data'); xlabel('Wire Length'); ylabel('Die Height'); legend('Raw Data', 'Centered Data', 'Location', 'best');
% Step 5: Set axis limits to ensure both plots are visible xlim([-max(WireLength) max(WireLength)]); % Set x-axis limits ylim([-max(DieHeight) max(DieHeight)]); % Set y-axis limits
% Step 6: Add x and y axes ax = gca; % Get current axes ax.XAxisLocation = 'origin'; % Set x-axis to the origin ax.YAxisLocation = 'origin'; % Set y-axis to the origin ax.XColor = 'k'; % Set x-axis color ax.YColor = 'k'; % Set y-axis color
% Step 7: Add a grid for better visualization grid on;
% Step 8: Display the plot hold off; % Release the hold on the current plot
Please see attached plot.
Updated code#2
Comparison of raw data and centered data
% Step 1: Define the raw data WireLength = [1, 4, 5, 6, 8, 10, 12, 14, 13, 18, 19, 22]; DieHeight = [125, 110, 287, 200, 350, 280, 400, 370, 480, 420, 540, 518];
% Step 2: Center the data meanWireLength = mean(WireLength); meanDieHeight = mean(DieHeight);
centeredWireLength = WireLength - meanWireLength; centeredDieHeight = DieHeight - meanDieHeight;
% Step 3: Create the figure window figure; % Create a new figure window
% Step 4: Create the first subplot for raw data subplot(1, 2, 1); % 1 row, 2 columns, first subplot scatter(WireLength, DieHeight, 'filled', 'MarkerFaceColor', 'b'); title('Raw Data'); xlabel('Wire Length'); ylabel('Die Height'); xlim([-max(WireLength) max(WireLength)]); % Set x-axis limits ylim([-max(DieHeight) max(DieHeight)]); % Set y-axis limits grid on; % Add grid for better visualization ax1 = gca; % Get current axes for raw data ax1.XAxisLocation = 'origin'; % Set x-axis to the origin ax1.YAxisLocation = 'origin'; % Set y-axis to the origin ax1.XColor = 'k'; % Set x-axis color ax1.YColor = 'k'; % Set y-axis color
% Step 5: Create the second subplot for centered data subplot(1, 2, 2); % 1 row, 2 columns, second subplot scatter(centeredWireLength, centeredDieHeight, 'filled', 'MarkerFaceColor', 'r'); title('Centered Data'); xlabel('Centered Wire Length'); ylabel('Centered Die Height'); xlim([-max(centeredWireLength) max(centeredWireLength)]); % Set x-axis limits ylim([-max(centeredDieHeight) max(centeredDieHeight)]); % Set y-axis limits grid on; % Add grid for better visualization ax2 = gca; % Get current axes for centered data ax2.XAxisLocation = 'origin'; % Set x-axis to the origin ax2.YAxisLocation = 'origin'; % Set y-axis to the origin ax2.XColor = 'k'; % Set x-axis color ax2.YColor = 'k'; % Set y-axis color
% Step 6: Adjust layout for better visibility sgtitle('Comparison of Raw Data and Centered Data'); % Add a super title for the figure
Please see attached plot.
Explanation
*The subplot(1, 2, 1) and subplot(1, 2, 2) commands create a 1-row by 2-column grid of subplots. The first subplot is designated for the raw data, while the second subplot is for the centered data.
*Each subplot contains a scatter plot. The first subplot visualizes the raw data in blue, while the second subplot visualizes the centered data in red.
*Each subplot has its own title and axis labels to clearly indicate what data is being represented.
*Axis Limits and Grid: The axis limits are set so that all data points are visible, and grids are added for better readability.
*The sgtitle function is used to add a super title to the entire figure, providing context for the comparison.
The reason for providing two codes is because then another comment will be posted mentioning that I wanted two plots next to each other. So, to make it easy for you, I provided both codes to suit your preferences. Hope this answers your question.