MATLAB Answers

Scatter plot with categorical x axis

18 views (last 30 days)
Zeynab Mousavikhamene
Zeynab Mousavikhamene on 25 Dec 2019
I need to make a plot which has categorical x.
Here is what I am trying to produce:
1.JPG

  3 Comments

Zeynab Mousavikhamene
Zeynab Mousavikhamene on 25 Dec 2019
Why you assign 5 to x? As I said, I want the x to be categorical.
Benjamin Bondsman
Benjamin Bondsman on 25 Dec 2019
You can also let the x axis to follow the y-axis as :
y=linspace(1,2,10)
x=length(y)
plot(x,y,'ro')
Zeynab Mousavikhamene
Zeynab Mousavikhamene on 25 Dec 2019
Thank you but In this script:
y=linspace(1,2,10)
x=length(y)
plot(x,y,'ro')
x=10 not categorical.

Sign in to comment.

Answers (1)

Benjamin Bondsman
Benjamin Bondsman on 25 Dec 2019
Hello,
Start by defining the value of the x axis, based on the figure you have only one value, while the value of y-axis varies.
x= any value
y=linspace(1,2,10)
plot(x,y,'ro')
grid minor
xlabel('name')
ylabel('name')

  1 Comment

Zeynab Mousavikhamene
Zeynab Mousavikhamene on 25 Dec 2019
Thanks Benjamin. As I mentioned, I need the x to be 'categorical' not numerical. The code you shared is simply giving the x a numerical valeusand then changing the label.

Sign in to comment.

Sign in to answer this question.

Tags


Translated by