Minor grid-lines spacing issue
54 次查看(过去 30 天)
显示 更早的评论
I have created a GUI using GUIDE and have two checkboxes, where one toggles minor and the other toggles major gridlines. They both work by activating the appropriate lines, but the minor grid is exactly under the major. (So in effect only the major are visible.)
How can I fix this issue so that minor grid-lines appear in between the major as would be expected?
Note: I am using MATLAB 2015a
Major Grid Active
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162125/image.jpeg)
Minor Grid Active
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162126/image.jpeg)
Required Grid
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162127/image.jpeg)
0 个评论
采纳的回答
Geoff Hayes
2017-3-28
Ben - how are you enabling and disabling the grid lines? If you are checkboxes are named checkbox1 and checkbox2 for the major and minor grid lines respectively, then the callbacks for both would be
function checkbox1_Callback(hObject, eventdata, handles)
if get(hObject,'Value') == 1
grid(handles.axes1,'on');
elseif get(handles.checkbox2,'Value') == 0
grid(handles.axes1,'off');
end
function checkbox2_Callback(hObject, eventdata, handles)
if get(hObject,'Value') == 1
grid(handles.axes1,'minor');
else
grid(handles.axes1,'minor');
if get(handles.checkbox1,'Value') == 0
grid(handles.axes1,'off');
end
end
We just need to add special cases to ensure that the major grid lines are turned off or left on depending upon whether the minor grid lines are off. See the attached code for an example.
5 个评论
Geoff Hayes
2017-3-30
Ben - when I run your code, I can see the major and minor grid lines (they behave as expected). Am I misunderstanding something?
更多回答(1 个)
Omanshu Thapliyal
2017-3-28
Another workaround apart from the answer above could be to specify the 'XMinorTickValues'. This lets you control the resolution of the minor grid. You could do so by getting the axis handle as
ax = gca;
ax.XMinorGrid = 'on';
ax.XAxis.MinorTickValues = 260:10:380;
You could set the minor grid resolution in the following part of your callback and change the minor grid lines to wherever you want them to be.
if get(hObject, 'Value') == 1
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!