Change multiple axis color and adding minor plot tick
3 次查看(过去 30 天)
显示 更早的评论
I'm having issues in changing settings of different plots with multiple axis.
Tasks:
1- add minor ticks to the first plot
2- change the color size of the LEFT Y-AXIS in the second plot
Plots are generated by a model output rather than my intention of creating codes to generate those plots.
Can you please provide general codes to change these settings?
2 个评论
回答(1 个)
Deepak
2024-9-10
I understand that you are using a model that generates two subplots with multiple axes in them. Now, you want to add minor ticks to the first subplot and change the color and size of the left y-axis of the second subplot.
To accomplish this task, we will use “findall” function in MATLAB to retrieve all graphics objects and store them in a variable “axesHandles”. Next, we can get different axes from “axesHandles” variable and store them as the variables “ax1” and “ax2”.
Now, to add minor ticks to first subplot, we can set the “XMinorTick” and “YMinorTick” property of “ax1” object to “on”. Also, to change the color and size of the left y-axis of the second subplot, we can update the “Color” and “FontSize” properties of the “ax2” object.
Here is the MATLAB code that addresses these tasks:
fig = gcf; % Get the current figure
axesHandles = findall(fig, 'Type', 'axes');
% findall retrieves handles in reverse order of creation
ax1 = axesHandles(2); % First subplot axes
ax2 = axesHandles(1); % Second subplot axes
% Add minor ticks to the first plot
ax1.XMinorTick = 'on';
ax1.YAxis(1).MinorTick = 'on';
% Change the color and font size of the left Y-axis in the second plot
ax2.YAxis(1).Color = 'g';
ax2.YAxis(1).FontSize = 14;
Attaching the documentation of “Axes Properties” and “findall” function in MATLAB for reference:
I hope this was informative for you.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Model, Block, and Port Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!