Heisenberg
Heisenberg

Reputation: 147

Plot a set of negative data in the "positive" Y-axis

I have a set of data I want to plot in MATLAB, the problem is that this set of data is all negative. I want to plot it in the Y-axis as if it was positive so the plot remains on the first quadrant, and I also want that the values show as negative.

I obviously tried:

plot(x,-y);

But this does not work because it plots on the first quadrant, but the values are converted into positive.

Any help on how to do this? I have searched documentation and forums and I couldn't find it.

Upvotes: 4

Views: 1766

Answers (2)

mabe
mabe

Reputation: 135

You can manually set the labels of your y-axis. Here's an example solution:

x = 1:10;
y = -1:-1:-10;

plot(x,abs(y))
ax = gca;
ax.YTick = abs(y);
ax.YTickLabel = num2cell(y);

Upvotes: 1

mikkola
mikkola

Reputation: 3476

Perhaps you are looking to reverse the direction in which the values on the y-axis grow?

x = -rand(100,1); %// some negative data
figure;
ah = axes;
plot(1:100, x);
%// reverse the direction in which values on y-axis increase
set(ah,'ydir','reverse')

For more, see axes properties, especially XDir, YDir, and ZDir.

Upvotes: 2

Related Questions