Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How can I have thicker axis lines on only certain values using surfc?

3 Ansichten (letzte 30 Tage)
Arran
Arran am 28 Jul. 2014
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
I'm using surfc to plot a 42x42 graph, which is then viewed from the top down. There is a meaningful difference between every 7 values, and as such I would like the x and y axis lines to be thicker for every 7th value (i.e. 7,14,21,28...). This would create a 7x7 grid within the 42x42. Is there an easy way to do this?

Antworten (1)

Ben11
Ben11 am 28 Jul. 2014
Bearbeitet: Ben11 am 28 Jul. 2014
Here is a simple way, drawing line objects at evenly spaced locations on your axis. I generate a dummy 2D plot but you can do the same with your surfc plot:
clear
clc
x = 1:15*pi; % dummy data to plot
A = 0:7:42; % generate regularly spaced values.
plot(abs(42*sin(x)));
xlim = get(gca,'XLim'); % get axis x limits
ylim = get(gca,'YLim'); % get axis y limits
hold all
for k = 1:7 % number of lines
line('XData',[A(k) A(k)],'YData',[ylim(1) ylim(2)],'LineWidth',1.5);% vertical lines
line('XData',[xlim(1) xlim(2)],'YData',[A(k) A(k)],'LineWidth',1.5); %
end
set(gca,'XLim',[0 42],'YLim',[0 42],'XTick',0:7:42,'YTick',0:7:42);
hold off
This results is the following:
Hope that helps! Note that you can also use
grid on
to visualize dotted gridlines.
If it's not what you meant please ask!
  3 Kommentare
Ben11
Ben11 am 28 Jul. 2014
Yes you can set the gridlines to full instead of dashed with this after your first call to plot:
set(gca,'gridlinestyle','-')
and then replace the last 2 lines of my answer with these:
set(gca,'XLim',[0 42],'YLim',[0 42]'XTick',0:1:42,'YTick',0:1:42);% i.e. remove the change to'XTick' and 'YTick'
hold off
grid on
Then your grids will appear full and the thicker lines added in the loop will as well. Is it what you mean? If not please ask :)

Diese Frage ist geschlossen.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by