Hi guys,
I'm reading a csv table into matlab and then plotting some data values.
My data is Education vs Age.
X -axis is the education and Y-axis is the age. Or I can have it vice versa if it's better.
However, I want to fix Y-axis so that range/interval are readatable. Below is my code and screen shot of my table.
If you look at the y-axis the numbers are all bunched up. I want to see some correct spacing.
For the data that I'm displaying the Y-axis is within the range of 18 - 60.
Thank you for your prompt response and assistance.
x = T2{1:3,4}
y = T2{1:3,1}
plot(x,y, 'LineStyle','none','Marker', 'o', 'MarkerSize',3)

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 6 de Abr. de 2020
You can specify the location of YTicks. For example
ax = gca;
ax.YTick = decimate(ax.YTick, 5); % it will reduce the number of ticks by 5
or
ax = gca;
ax.YTick = ax.YLim(1):10:ax.YLim(2); % will give space of 10 between Ticks.

4 comentarios

Hi Ameer,
Thank you for your answer. My other question is where do I insert this part of the code you gave me. This is how I tested your code. see below. But I still get the same result.
When simply run your part of the code I get an empty graph.
x = T2{1:3,4}
y = T2{1:3,1}
ax = gca;
ax.YTick = ax.YLim(1):10:ax.YLim(2);
plot(x,y, 'LineStyle','none','color','red','Marker', 'o', 'MarkerSize',5)
Ameer Hamza
Ameer Hamza el 8 de Abr. de 2020
Editada: Ameer Hamza el 8 de Abr. de 2020
Please place these lines after you code. Like this
x = T2{1:3,4}
y = T2{1:3,1}
plot(x,y, 'LineStyle','none','Marker', 'o', 'MarkerSize',3)
ax = gca;
ax.YTick = ax.YLim(1):10:ax.YLim(2);
Or a more robust one like this
x = T2{1:3,4}
y = T2{1:3,1}
figure;
ax = axes();
plot(x,y, 'LineStyle','none','Marker', 'o', 'MarkerSize',3)
ax.YTick = ax.YLim(1):10:ax.YLim(2);
Emmanuel Matata Bili Bili
Emmanuel Matata Bili Bili el 8 de Abr. de 2020
Thanks Ameer,
During troubleshooting I found that one of my columns was a categorical data instead of numeric.
I made the change and it worked fine. I tried your solution also and it worked fine.
Cheers!
Ameer Hamza
Ameer Hamza el 8 de Abr. de 2020
Glad to be of help.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Axes Appearance en Centro de ayuda y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by