Can anybody help with Python graph plotting please!
Discussion
I'm plotting a graph which has a log scale on the 'x' axis.
This works, however the numeric output along the 'x' axis is now in scientific notation.
How can I plot a log graph, but with decimal notation?
This is my graph code:
Thanks in advance.

This works, however the numeric output along the 'x' axis is now in scientific notation.
How can I plot a log graph, but with decimal notation?
This is my graph code:
#!/usr/bin/python
import matplotlib.pyplot as plt
import numpy as np
x, y = np.loadtxt('boom.txt', delimiter=',', unpack=True)
plt.figure(figsize=(20,10))
plt.plot(x,y, label='Frequency response')
plt.grid(b=True, which='both', color='0.65', linestyle='-')
plt.minorticks_on()
plt.ylim(ymin=-10)
plt.ylim(ymax=1)
plt.grid(True)
plt.xscale('log')
plt.xlabel('Frequency')
plt.ylabel('dB')
plt.title('Response')
plt.legend()
plt.show()
Thanks in advance.
After much research... Solved!

#!/usr/bin/python
import numpy as np
from matplotlib.pyplot import *
def log_10_product(x, pos):
"""The two args are the value and tick position.
Label ticks with the product of the exponentiation"""
return '%1i' % (x)
figure(figsize=(20,10))
# Axis scale must be set prior to declaring the Formatter
# If it is not the Formatter will use the default log labels for ticks.
ax = subplot(111) # defines sub plot
ax.set_xscale('log')
formatter = FuncFormatter(log_10_product)
ax.xaxis.set_major_formatter(formatter)
ax.yaxis.set_major_formatter(formatter)
x,y = np.loadtxt('boom.txt', delimiter=',', unpack=True)
# Plot
ax.plot(x, y)
ax.grid(b=True, which='both', color='0.65', linestyle='-')
ax.set_ylim(ymin=-10)
ax.set_ylim(ymax=1)
ax.minorticks_on()
grid(True)
xlabel(r"Frequency", fontsize = 12)
ylabel(r"dB", fontsize = 12)
title('Response')
show()
Edited by TonyRPH on Wednesday 29th August 16:27
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


