robf
robf

Reputation: 53

Custom axis scales - "Reverse" logarithmic?

Sorry about the poor title ;)

I'm trying to recreate a matlab plot I've come across in some other work, but I don't quite understand the scale they are using. The y axis increments are as follows (from the top [+ve y]):

0.9999, 0.999, 0.99, 0.9, 0

I can use semilogy to plot a logarithmic graph, but this is kind of the wrong way round; my increments go

1, 0.1, 0.01, 0.001, etc

which is actually 1 - i, where i is the increments I actually want! I don't entirely understand how to describe this type of plot anyway; can anyone help?

Upvotes: 5

Views: 11381

Answers (2)

fushan
fushan

Reputation: 429

Using the same idea of @Jonas, I rewrite the code in a newer version of matplotlib. Suppose y = np.array([0.1, 0.5, 0.9, 0.99, 0.999])

plt.yscale('log')
plt.gca().invert_yaxis()
plt.plot(x, 1-y)
plt.gca().set_yticklabels(1-plt.gca().get_yticks())

Upvotes: 2

Jonas
Jonas

Reputation: 74940

To plot the axes the way you want to, you have to do three steps: (1) plot 1-y, (2) reverse axes (3) relabel axes

y = [0.4 0.8 0.99 0.9999];

%# plot 1-y 
plot(1-y) %# alternatively use semilog, then you won't have to adjust 'yscale' below

%# reverse y-axis
set(gca,'ydir','reverse','yscale','log')

%# if necessary, set the axis limits here

%# relabel y-axis
set(gca,'yticklabel',num2str(1-10.^str2num(get(gca,'yticklabel'))))

enter image description here

Upvotes: 6

Related Questions