Hi @Bo ,
You mentioned, “ What I need is to adjust the face transparency of the data point. However, it seems like the function 'errorbar' does not support this option: I tried 'MarkerFaceAlpha' but this is not recognized. Could someone give advice? “
First of all, you should follow @dpb advice. I agree with his comments after experimenting with code.
Now, let me address your query regarding adjusting marker face transparency when using the errorbar function in MATLAB, it's important to note that errorbar indeed lacks direct support for transparency properties like MarkerFaceAlpha. Instead, you can achieve the desired effect using a workaround by utilizing the scatter function (again as referenced by @dpb) in combination with errorbar. First, use the errorbar function to plot your data along with error bars without markers. Then, use the scatter function to overlay markers at the same data points with the desired transparency settings. Here is how you can implement this:
% Sample data x = linspace(0, 10, 10); % X data y = sin(x); % Y data err = 0.1 * ones(size(y)); % Error values
% Step 1: Plot error bars without markers figure; % Create a new figure e = errorbar(x, y, err, 'k-.'); % Black dashed line for error bars
% Step 2: Overlay transparent markers hold on; % Retain current plot scatter(x, y, 100, 'k', 'filled', 'MarkerFaceAlpha', 0.5); % Adjust alpha as needed hold off; % Release hold on current plot
% Additional formatting (optional) xlabel('X-axis'); ylabel('Y-axis'); title('Error Bar Plot with Transparent Markers'); legend('Error Bars', 'Data Points');
Please see attached.
For more information on MarkerFaceAlpha defined in scatter function, please refer to
https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.scatter-properties.html
So, in the above code, sample data for x, y and error values (err) is defined. The errorbar function is called with k- which specifies a black dash-dot line for error bars. The scatter function is used to overlay filled circles (k for black) at each data point with a specified size (100 points) and a transparency level (MarkerFaceAlpha', 0.5). You can adjust this alpha value between 0 (fully transparent) and 1 (fully opaque) according to your preference.
Using this method allows you to have complete control over both the appearance of your error bars and the transparency of your markers. The combination of these two functions gives you more flexibility than using errorbar alone. If you frequently need to adjust marker properties such as transparency or color dynamically based on data conditions, consider creating a custom plotting function or script that incorporates this approach for efficiency.
Hope this helps.
If you have any further questions or need additional assistance, feel free to ask!