need better grid solution for labeled data

7 views (last 30 days)
Jonathan
Jonathan on 7 Sep 2011
Situation:
MATLAB Version: 2007a
I am writing a report with many similar plots. (not similar enough for copy-and-paste) I would like to present a grid of information using imagesc. Each row and column has an integer label, and the numbers are all sequential. *Problems: *
I can either have the gridlines I like, or the label placement I like:
grid solution:
set(gca,'Xtick',[0.5:1:numel(x)]);
set(gca,'Ytick',[0.5:1:numel(y)]);
grid;
This puts the grid in the right place, but the lables are off of the data.
label solution:
set(gca,'Xtick',[0:numel(x)]);
set(gca,'Ytick',[0:numel(y)]);
This has the right labels, but the gridlines bisect the data cells.
failed solutions:
grid minor solution
adding the minor grid to the screen adds several lines that run through the cells on one axis.
line() solution: I tried using line(), but it doesn't accept the typical plot arguments like '--' or color modifications to make the grid black;
possible (but painful) solutions:
plot() solution:
I could hold the plot and use plot() to scatter plot all of the grid lines I would like.
text() solution:
What I will likely do is use the code from the grid solution, turn the axis off, then place the labels using text() and a for loop.
Ynum = TBD; % number required to put text in correct location
Xnum = TBD; % number required to put text in correct location
Ysep = TBD; % separation between Y values
Xsep = TBD; % separation between X values
set(gca,'Xtick',[0.5:1:numel(x)]);
set(gca,'Ytick',[0.5:1:numel(y)]);
grid;
axis off;
for n = 1:Ysep:numel(x)
text(n,-Ynum,num2str(n))
end
for n = 1:Xsep:numel(y)
text(n,-Xnum,num2str(n))
end
The problem with this is then that different lengths of label will change the alignment of text to the cells.
Request:
I'm looking for a more elegant way to do this that will not require lots of tweaking to get the right alignment of data and labels.
if there isn't a solution right now, I'll go ahead and ask for a new function called GRIDHOLD that leaves the grid in place when you change XTick or YTick.
Thank you.
Also, add a preview button to your website, so it doesn't generate a preview after any typing. This behavior dramatically slows down the apparent speed of your website.

Answers (0)

Community Treasure Hunt

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

Start Hunting!