8

Matlab is displaying a black border around a plot and I would like to remove it. I think i should be using something like:

set(Figure#,'PropertyName',PropertyValue);

But I'm not sure what PropertyName or PropertyValue should be used...

Edit:

I tried all of the suggestions including:

set(gca,'box','off');
set(gca,'xcolor','w','ycolor','w','xtick',[],'ytick',[]);
axis off;

The figure still has a black boarder and looks like this:

enter image description here

Edit 2: This is a simplified package that reproduces the black box. Run the script called "runPlot". Here it is: http://dl.dropbox.com/u/8058705/plotTest.zip I can't figure out why the box is still visible. This might be due to the line in "plotTEC.m"

axis([-.65 .6 .25 1.32]) % hardwiring axis length since the coastline runs off of the plot

@Pursuit: If I use "plot browser" I get a recursive error....I am not familiar with the matlab plotting package but this seems strange. Does anyone else get this error? Again, thank you guys for your advise!

Does anyone have any other suggestions?

Thanks in advance!

GPSmaster
  • 844
  • 3
  • 15
  • 31
  • I think that you'll need to manually investigate the figure to determine where the lines are being drawn. See edited answer below for details. – Pursuit Feb 10 '12 at 21:42

4 Answers4

16

You want to experiment with the properties of the axis. Some properties of interest.

xcolor  %The color of the x-axis line and the x axis labels
ycolor  %
box     %'on', or 'off' indicating if one or both sides of a plot should have lines
xtick   %Where to place the labels
ytick

For a completely bare plot, use:

figure
set(gca,'xcolor','w','ycolor','w','xtick',[],'ytick',[])

To set the figure background to white as well

set(gcf,'color','w')

Depending on your exact problem, you can try the 'box' property, to see how it affects your plots

set(gca,'box','on')
set(gca,'box','off')

If you want to turn off the actual plots lines but keep the plot labels then I am not aware of a simple solution. I think that I would need to remove the axes as described above, and then manually add labels using the text function.


Edit: As I just learned from this question, Plot Overlay MATLAB you can also try

axis off
axis on

Which I think is equivalent to

set(gca,'visible','off')
set(gca,'visible','on')

Edit 2:

If nothing else works, activate the "plot browser" in your figure. Use "view" --> "plot browser". From the plot browser panel, uncheck each object until you figure out which object is drawing the lines that you need to remove.

Then double click on the offending object to bring up the "property editor" panel, and mostly likely click "More properties" to view all possible properties of that object. From that view you can (hopefully) figure out what object is drawing the offending lines.

After you have figured out the object and property to edit, you can probably figure out where in the code that object is created, and set the property programmatically.

Community
  • 1
  • 1
Pursuit
  • 12,285
  • 1
  • 25
  • 41
  • Awesome! Thanks. Do you know if there is a list of matlab figure properties somewhere? – GPSmaster Feb 06 '12 at 20:55
  • 1
    @GPSmaster - You can always see an object's properties using the GET command, e.g. `get(gcf)` or `get(gca)`. – b3. Feb 06 '12 at 20:58
  • 1
    In addition to `get` (hands down the most useful tool), you can search the documentation. EG `docsearch figure properties`, or `docsearch axis properties`. If you can't find something you think should be there, also try turning on the undocumented goodies ... `set(0, 'hideundocumented','off')`, and then rerun your `get(..)` commands. – Pursuit Feb 06 '12 at 21:02
  • @Pursuit: See "Edit 2" in my original post. Thank you! – GPSmaster Feb 13 '12 at 23:27
  • @Pursuit `axis off` and `set(gca,'visible', 'off')` are NOT the same. The former only hides the axes. The latter hides both the axes and the title (maybe more, idk). whew. I came across this post trying to troubleshoot my missing title! – Dominik Nov 01 '12 at 02:48
6

Try:

set(gca, 'Box', 'off');
b3.
  • 7,094
  • 2
  • 33
  • 48
3

Solution to remove 'gray' background in imagesc

I = imread('imgname.jpg');
[rows columns] = size(I);
posX = 100; posY = 100; %you can set any value for posX and posY - try to keep it on screen
f = figure (1);
imagesc(I);
set(gcf,'Position',[posX posY columns rows]);
set(gca,'units','pixels');
set(gca,'units','normalized','position',[0 0 1 1]);
axis off;
axis tight;

This should save the image with same size as that of the original, using imagesc. Cheers!

dbs
  • 126
  • 3
  • 1
    Save the image with either 'Save' icon or File->'Save As'. Matlab print, saveas, etc. will result in different image size. – dbs Jul 15 '13 at 11:21
  • That's true and annoying, but there's `export_fig` ([found here](http://www.mathworks.com/matlabcentral/fileexchange/23629-export-fig)) which does a really good job of saving plots in general. Nice to have something to save plots programmatically. – whlteXbread May 15 '14 at 01:48
0

set( gca , 'Visible' , 'off' );