Is there any way to have grid on as default?

Hi!
Is there any way to make matlab plot all my figures (bode, step, simple plots etc.) with grids? I find it much better.
Thanks!

 Respuesta aceptada

Mehmed Saad
Mehmed Saad el 30 de Abr. de 2020
set(groot,'defaultAxesXGrid','on')
set(groot,'defaultAxesYGrid','on')
figure,plot(1:10)

11 comentarios

Elia D'Orazio
Elia D'Orazio el 17 de Mayo de 2020
I tried as you suggest but every time i reopen matlab "grid on" it is not default anymore.
Rik
Rik el 17 de Mayo de 2020
Have you tried putting it in startup.m?
Netanel Freinkel
Netanel Freinkel el 19 de Mayo de 2020
Hi!
Thanks for the answer.
I did try it (including putting them in the startup file).
Does do the job for every "plot" command, which is helpful.
Thing is I will be happy to find a way to do that for every kind of figure (bode, step, etc.), which the solution above doesn't.
Thanks again!
Elia D'Orazio
Elia D'Orazio el 1 de Jun. de 2020
Yeeees, it worked! I wasn't aware of startup.m, thank you.
Marco Lepidi
Marco Lepidi el 21 de Dic. de 2021
Hi sorry, what does 'putting in startup.m' mean?
And how can i have minorgrids and minorticks by default?
@Marco Lepidi startup.m is a file that will be run when you start up Matlab. You can use the line below to open it (and create it if it doesn't exist).
edit(fullfile(userpath,'startup.m'))
See this doc page for more information.
Marco Lepidi
Marco Lepidi el 21 de Dic. de 2021
Okay thank you very much. Do you know what i have to do to show minorgrids and minorticks by default?
Rik
Rik el 21 de Dic. de 2021
Did you try putting the code in the answer in your startup file? What was the result?
Marco Lepidi
Marco Lepidi el 21 de Dic. de 2021
It works for grid and ticks but not for minorgrids
Marco Lepidi
Marco Lepidi el 21 de Dic. de 2021
sorry minorticks, but it doesn't work for minorgrid
Nicholas Tarasenko
Nicholas Tarasenko el 3 de Feb. de 2022
Editada: Nicholas Tarasenko el 3 de Feb. de 2022
I wanted to provide a second method that follows closely to @Mehmed Saad. I have a file called "startup.m" in my MATLAB paths. In the startup file I set the default for all of my plots for every session. I did this so that I don't have to remember to include the default plot syntax in every script.
My startup script has the following defaults:
set(0,'defaultaxesfontname','Helvetica')
set(0,'defaulttextfontname','Helvetica')
set(0,'defaultaxesfontsize',15)
set(0,'defaultaxesfontweight','Bold')
set(0,'defaulttextfontsize',15)
set(0,'defaulttextfontweight','Bold')
set(0,'DefaultLineLineWidth',1.2)
set(0,'DefaultFigureColor', 'white');
set(0,'defaultAxesXGrid','on')
set(0,'defaultAxesYGrid','on')

Iniciar sesión para comentar.

Más respuestas (1)

Guilherme Scofano
Guilherme Scofano el 20 de Feb. de 2026
TL;DR:
ctrlpref
Then "Style" tab > Show grids by default.
The Control Toolbox plot functions (bode, bodeplot, pzmap, step, stepplot, lsim, etc.) have a different set of configurations, so changing properties in groot, generally does not work.
If you want to change default settings (grids on/off, title font size, etc.) for these functions, you have to go to the "Control System and System Identification Toolbox Preferences" dialog window.

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 30 de Abr. de 2020

Respondida:

el 20 de Feb. de 2026

Community Treasure Hunt

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

Start Hunting!

Translated by