Change multiple axis color and adding minor plot tick

5 vues (au cours des 30 derniers jours)
Filippo Bocchi
Filippo Bocchi le 29 Avr 2021
Réponse apportée : Deepak le 10 Sep 2024
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 commentaires
Jonas
Jonas le 29 Avr 2021
can you provide an image or code of your current state please?
Filippo Bocchi
Filippo Bocchi le 29 Avr 2021
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?

Connectez-vous pour commenter.

Réponses (1)

Deepak
Deepak le 10 Sep 2024
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.

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by