MATLAB Answers

0

How to make grid lines visible while Axis is invisible?

Asked by Chaitanya Jha on 24 Jun 2019 at 15:18
Latest activity Answered by Chaitanya Jha on 26 Jun 2019 at 8:54
Hi, I am developing a GUI in which I have two plots, current and voltage (see below). I am using 3 axes, a big one whos X-Axis displays the time, two smaller axes on top of this big axes, I plot current and voltage in these two smaller top axes. The visibility of the smaller axes is set to 0 and only the visibility of their Y-Axis is switched on afterwards. This gives it an impression that both current and voltage are plotted on the bigger axes on which X-Axis serves as time axis. I can do all this, however, I would like to switch on the YGrid of the two smaller axis while keeping the axis itself invisible. I have tried different methods, such as setting the YGrid property to 'on' and using 'grid on' command, but nothing works. Can it be done?

  4 Comments

Show 1 older comment
Hi Pullak, the entire code is quite big, I will provide the basic version of the code to create the three axis like above. Many of the things in the code below is just cosmetics, the important thing is to make the axes invisible first and then make only its YAxis visible (see below AxLft and AxRit).
AxBse = axes('Parent',S.F,'XGrid','on','YGrid','on','GridLineStyle',':',...
'XColorMode','manual','YColorMode','manual',...
'XLimMode','manual','YLimMode','manual','GridColorMode','manual',...
'Box','on','Units','normalized','FontName',...
'Courier New','FontWeight','bold',...
'FontSize',10,'FontAngle','normal','LabelFontSizeMultiplier',1,...
'LineWidth',1,'Position',[0.53 0.06 0.43 0.9]);
AxBse.Toolbar.Visible = 'off';
AxBse.XAxis.Exponent = 0;
AxBse.GridColor = 'k';
AxBse.XColor = 'k';
AxBse.XLabel.FontName = 'Courier New';
AxBse.XLabel.FontWeight = 'bold';
AxBse.XLabel.FontSize = 12;
AxBse.XLabel.String = 'Time (ms)';
AxBse.YAxis.Visible = 0;
AxLft = axes('Parent',S.F,'XGrid','off','YGrid','on','GridLineStyle','-',...
'XColorMode','manual','YColorMode','manual',...
'XLimMode','manual','YLimMode','manual',...
'Box','off','Units','normalized','FontName',...
'Courier New','FontWeight','bold',...
'FontSize',10,'FontAngle','normal','LabelFontSizeMultiplier',1,...
'TitleFontSizeMultiplier',1,'LineWidth',1,...
'Position',[0.53 0.51 0.43 0.45]);
VltPL = plot(rand(1,10),'Parent',AxLft,'Color','b');
AxLft.Toolbar.Visible = 'off';
AxLft.Visible = 0;
AxLft.YAxis.Exponent = 0;
AxLft.YColor = 'b';
AxLft.YLabel.FontName = 'Courier New';
AxLft.YLabel.FontWeight = 'bold';
AxLft.YLabel.FontSize = 12;
AxLft.YLabel.String = 'Voltage (mV)';
AxLft.YAxis.Visible = 1;
AxLft.NextPlot = 'add';
AxRit = axes('Parent',S.F,'XGrid','off','YGrid','off',...
'XColorMode','manual','YColorMode','manual',...
'XLimMode','manual','YLimMode','manual',...
'Box','off','Units','normalized','FontName',...
'Courier New','FontWeight','bold',...
'FontSize',10,'FontAngle','normal','LabelFontSizeMultiplier',1,...
'TitleFontSizeMultiplier',1,'LineWidth',1,...
'Position',[0.53 0.06 0.43 0.45]);
CurPL = plot(rand(1,10),'Parent',AxRit,'Color','r');
AxRit.Toolbar.Visible = 'off';
AxRit.Visible = 0;
AxRit.YAxisLocation = 'right';
AxRit.YAxis.Exponent = 0;
AxRit.YColor = 'r';
AxRit.YLabel.FontName = 'Courier New';
AxRit.YLabel.FontWeight = 'bold';
AxRit.YLabel.FontSize = 12;
AxRit.YLabel.String = 'Current (pA)';
AxRit.YAxis.Visible = 1;
AxRit.NextPlot = 'add';
Chaitanya - to be clear, the axes object is hidden (visible property set to off or false) yet you want to show the YGrid lines for that hidden axes object?
Yes Geoff. I figured that if I can only show the Y-Axis while the rest of the Axes is hidden then there might be a way to just enable the visible property of the YGrid for the same axis without making the the rest of the Axes (i.e. XGrid, X-Axis, Background, etc) visible.

Sign in to comment.

Products


Release

R2018b

2 Answers

Answer by Chaitanya Jha on 26 Jun 2019 at 8:54
 Accepted Answer

I found the workaround of this problem by chaning the background of the axes to transparent using below code
set(Ax,'Color','none');

  0 Comments

Sign in to comment.


Answer by Jan
on 25 Jun 2019 at 14:37

The question is a little bit confusing for me. An invisible axes does not have visible properties. But you can create a visible axes and hide what you want:
ax = axes;
ax.XGrid = 'on';
ax.YGrid = 'on';
ax.XTick = [];
ax.YTick = [];
ax.XAxis.Visible = 'off';
ax.YAxis.Visible = 'off';

  1 Comment

Hi Jan, I can understand your confusion. Creating a visible axes means the background of the axes is still visible, I would like to make the background and everything else invisible, and then make only a few selected properties, such as YAxis and YGrid, visible.

Sign in to comment.