How do I change plot line widths?

I'm trying to plot two arrays of values and change the width of the resulting line, however I can't seem to get it to work. I've tried several approaches and nothing seems to be yielding any results.
plot(X_a,Y_a,'LineWidth',10);

6 Comments

The obvious question is:
  • What are ‘X_a’ and ‘Y_a’,(vectors, matrices, something else?) and
  • What is the context of the code you are plotting them in?
This works when I plot it
X_a = 1:10
Y_a = sin(2*pi*X_a/10)
figure
plot(X_a, Y_a,'LineWidth',10)
figure
plot(X_a', Y_a','LineWidth',10)
so you are obviously not telling us some important information.
X_a and Y_a are initialized as matrices. This is part of a function that reads in a given equation to plot based on starting and stopping X values as well as a given step size for X with which to caluclate Y. X_a and Y_a are the storage arrays for plotting the values of X and Y at the end of the for loop calucations. Probably not the best way of going about it, but I digress.
Could you share a screen shot of the results of the line below?
plot(X_a,Y_a,'LineWidth',10);
Something's probably off with your input variables. Here's an example of input matricies that procude lines and a functioning width parameter.
X_a = rand(4,4);
Y_a = rand(4,4);
plot(X_a, Y_a, 'LineWidth', 4)
Do you have the plot() inside a loop where you are plotting just one single point, instead of AFTER the loop where you are plotting a bunch of values at once?
You should also specify the line style, like
plot(X_a, Y_a, 'b*-', 'LineWidth', 10); % Plot blue line with asterisk markers
to make sure you're plotting a line rather than just markers.
Got it working, for some reason my function wasn't updating when I called it to check my work. All set now. Thanks!
If the m-file containing your function is stored on a remote driver or server, sometimes you need to rehash the path after making changes to the m file before those changes take effect.
rehash path

Sign in to comment.

Answers (1)

Categories

Asked:

on 2 Feb 2019

Answered:

on 8 Jul 2021

Community Treasure Hunt

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

Start Hunting!