0

Hey.. I have run into a bit of a problem with my python code.. I have a set of values each for frequency and power-spectrum. I need to plot frequency v/s power-spectrum on Log scale. I was trying to store the logarithmic values of frequency and power-spectrum in 2 other variables and then plot them.. Any idea how that can be done?

1
  • 2
    Show us what you've got so far. Commented Mar 3, 2011 at 1:05

2 Answers 2

5

Assuming you've got a list of values you might use a simple list comprehension:

frequencies = [1, 2, 3, 4, 5]
import math
logOfFrequencies = [ math.log(x) for x in frequencies ]

Or

logOfFrequencies = map(math.log, frequencies)

If you have a numpy array of frequencies because you're using Matplotlib / Pylab to create your plots you can instead do:

import numpy
frequencies = numpy.arange(1, 5)
logOfFrequencies = numpy.log(frequencies)
Sign up to request clarification or add additional context in comments.

Comments

3

If you are only interested in plotting the data on a log scale, consider the matplotlib methods, loglog and semilogx and semilogy:

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.loglog

http://matplotlib.sourceforge.net/plot_directive/mpl_examples/pylab_examples/log_demo.py

This would allow you to avoid calculating the log of the various arrays and allow you to customize exactly how the various quantities are displayed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.