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 个评论
Jonas
Jonas 2021-4-29
can you provide an image or code of your current state please?
Filippo Bocchi
Filippo Bocchi 2021-4-29
I'm afraid I can't. I'm doing an academic project with a model that hasn't already been launched on the market, which is why I haven't posted a picture yet.
Can you just provide general codes for it?

请先登录,再进行评论。

回答(1 个)

Deepak
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.

类别

Help CenterFile Exchange 中查找有关 Model, Block, and Port Callbacks 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by