Take the 2-minute tour ×

I have two representations of the same function. The one shows it as a function of voltage, the other as a function of depth (a monotonous but complicated function). Depth can be expressed as a function of voltage. I would like to add something like a voltage axis to the depth representation but this does not seem to be possible.

How can I add vertical lines at increments of the voltage like -0.5, -1.0, -1.5, ... on the depth plot?

share|improve this question
have you checked the matplotlib gallery? –  Francesco Montesano Mar 21 '13 at 13:41
Could you post your code and also an representative image of what you'd like to achieve? –  David Zwicker Mar 21 '13 at 14:09
I checked the gallery. Here is link how it looks at the moment, I want to get rid of the upper graph and display the voltage information on the lower: dl.dropbox.com/u/226980/stackexchange.jpg –  sonium Mar 21 '13 at 14:24
And it should look like this: dl.dropbox.com/u/226980/enhanced.png or with a proper scale on top. –  sonium Mar 21 '13 at 14:39

1 Answer 1

I found that it is indeed possible to create a custom second axis on the top. The result looks like this: https://dl.dropbox.com/u/226980/solved.jpg

This works by using FixedLocator.

The whole code looks like this:

f = subplot(111)
p1 = plot(depth_samples,NtNdbulk, label = "relative concentration")
xlabel("depth [um]")

p2 = plot(depth_samples,Nt, color='r', label = "absolute concentration")   

p = p1 + p2

labs = [l.get_label() for l in p]
legend(p, labs, loc=0)

ax2 = twiny()
p1 = plot(depth_samples,NtNdbulk, alpha = 0) #invisible

l = matplotlib.ticker.FixedLocator(tick_depth*1e4) # Positions of the ticks
ax2.get_xaxis().set_ticklabels(ticks) # Voltages as displayed
xlabel("DLTS voltage during pulse")

share|improve this answer
Please accept your own answer. –  tcaswell Mar 31 '13 at 0:02

Your Answer


