Remove Dashed Grey Asymptote Lines From Plot

I have a plot of a few symbolic functions in matlab, and I'm getting some grey dashed lines. I'm going to guess that these are for asymptotes, which I expected. Is there a way to remove these lines?
Attached is my plot. The lines I'm talking about are at x = 4 and x = 0. Ignore the legend and other colors, that's another story.

3 件のコメント

Walter Roberson
Walter Roberson 2020 年 9 月 12 日
is this fplot or fimplicit?
dashed lines for fplot are discontinuities not asymptopes
Benjamin Blood
Benjamin Blood 2020 年 9 月 12 日
I used fplot. I guess you're right, it's a discontinuity. Do you know if there's a way to remove it?
mauricio
mauricio 2022 年 9 月 19 日
is there a way to change their color?

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2020 年 9 月 12 日

0 投票

If you let
h = fplot(expression, range)
then
h.NodeChildren(1).Visible = 'off';
will turn off the discontinuinity lines. (The gray dashed ones, at least. At the moment I do not recall the formula for any functions that generate the brown discontinuity lines. Possibly NodeChildren(2) for those.)

5 件のコメント

Benjamin Blood
Benjamin Blood 2020 年 9 月 17 日
Hi there, sorry for the delay in letting know if this worked. I wasn't able to hide the grey line. I tried turning off the visibility on all the node children, and it got rid of everything except the grey line.
Walter Roberson
Walter Roberson 2020 年 9 月 18 日
can you attach your actual code?
Benjamin Blood
Benjamin Blood 2020 年 9 月 18 日
Sure. Here it is. I've changed it a bit since I first asked the question, the new plot is attached. As I've commented in the code, g(1) is the only symbolic function I'm currently trying to plot.
%% Standard Housekeeping
clear all;
close all;
clc;
%% Define objective functions and constraints
syms x1 x2 f1(x1, x2) f2(x1, x2)
% Defining two objective functions
f1(x1, x2) = -0.4 * x1^2 - 4 * x1 - exp(x2^2);
f2(x1, x2) = -(x2 - 5.1/(4*pi^2) * x1^2 + 5/pi * x1 - 6)^2 - 10 * (1 - 1/(8*pi)) * cos(x1) - 10;
% Defining design constraints
g(1) = 2.5 * x1^2 + 0.5 * x1 * x2 - 3; % Only one I'm currently plotting
g(2) = -4 * x1 + 8 * x2^2 - 16;
g(3) = 6 * x1^2 + 2 * x2^2 + 8 * x1 * x2 - 2.5 *x1 - 4 * x2 - 12;
% Defining side cosntraints
x1L = -1.5;
x1U = 2;
x2L = -2;
x2U = 1;
%% Plotting constraints
hold on;
% Plotting g(1)
consPlot = fplot(solve(g(1), x2), [-10 10]);
consPlot.NodeChildren(1).Visible = 'off';
hold off;
And here is the resulting plot:
Walter Roberson
Walter Roberson 2020 年 9 月 18 日
Put a drawnow() before setting the Visible to off. If you set the visible to off before the drawnow then it will be reset to on when the plot renders.
... No, I do not know why this happens. I could make some guesses.
Oh, look at that, the line comes back again if you resize the plot. I think we can deduce that the rendering callbacks are turning the visibility on. You might want to add in a ResizeFcn callback to drawnow() and turn it invisible again after the axes changes. Or perhaps a PostSet listener on the axes Position property.
Benjamin Blood
Benjamin Blood 2020 年 9 月 19 日
Running drawnow works. Right now I'm just running those commands in the command window every time I resize the plot, but that works for now. Thank you for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

製品

リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by