Plot command changing the graph background and grid line colours in GUIDE
49 次查看(过去 30 天)
显示 更早的评论
Hi.
Im using GUIDE and have several axes components that I use to display graphs. One of them i want to have a dark background. I noticed when I set the background colour to my choice in the property inspector, when the GUI ran, it was correct. But as soon as I plotted the background went white.
so I tried to put the following in the opening function:
ax=axes(handles.axes1)
set(ax,'Color',[0.15 0.15 0.15])
grid on
ax.GridColor=[1 1 1];
ax.GridAlpha=0.5;
drawnow;
But again, when I plot my grapg (from a push button callback), it again turns back to default white.
Is there a way to stop the plot command changing the graph background and grid line colours?Is there a way to stop the plot command changing the graph background and grid line colours?
0 个评论
采纳的回答
Walter Roberson
2020-1-7
In MATLAB, when you use any "high-level" plotting command, MATLAB checks to see if you have specifically said that you want to add new graphics on top of existing graphics. If you have not indicated that, then if there is an existing axes, MATLAB clears the axes properties -- including properties such as background colors. For example if you do
ax=axes(handles.axes1);
plot(ax, [1 2 3], [3 2 1]);
pause(3)
plot(ax, 2, 2, 'r*');
then this would draw a diagonal line, wait three seconds, then clear the axes and then draw a single point at 2,2 . The above code does not draw a diagonal line, wait three seconds, and then add a red star to the existing plot.
In order to tell MATLAB that you want new graphics to go on top of existing graphics (that is, that you do not want the entire axes cleared), use hold on. For example,
ax=axes(handles.axes1);
set(ax,'Color',[0.15 0.15 0.15])
hold(ax, 'on')
plot(ax, [1 2 3], [3 2 1]);
pause(3)
plot(ax, 2, 2, 'r*');
hold(ax, 'off')
This sets the background color, then tells MATLAB that you want later drawing to go on top of existing drawing. Then it draws the diagonal line, waits three seconds, does not clear the axes, and adds a red * on top of the line. Then it tells MATLAB that unless it is told otherwise, it is okay for the next high level graphic operation to clear the axes.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!