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 Kommentare

Walter Roberson
Walter Roberson am 12 Sep. 2020
is this fplot or fimplicit?
dashed lines for fplot are discontinuities not asymptopes
Benjamin Blood
Benjamin Blood am 12 Sep. 2020
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 am 19 Sep. 2022
is there a way to change their color?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 12 Sep. 2020

0 Stimmen

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 Kommentare

Benjamin Blood
Benjamin Blood am 17 Sep. 2020
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 am 18 Sep. 2020
can you attach your actual code?
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 am 18 Sep. 2020
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 am 19 Sep. 2020
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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by