I need to plot a graph like this style, where the x-ticks have evenly space in the range of [0.1, 1, 10, 100, 1000].
My code looks like this:
x = np.array([0.3081, 1.2, 29.4, 29.4, 54.7, 29.4, 14.7, 7.8, 54.7, 68.0])
y =np.array( [94.92, 94.85, 92.61, 93.44, 94.86, 92.57, 94.88, 93.64, 94.99, 95.40])
plt.plot(x, y, 'b.')
plt.xticks(np.array([0.1, 1, 10, 100]))
plt.grid(True)
plt.show()
which generates a plot like this:
Any help or suggestions would be greatly appreciated!
You can use a matplotlib.pyplot
method xscale
and pass 'log' as an argument:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([0.3081, 1.2, 29.4, 29.4, 54.7, 29.4, 14.7, 7.8, 54.7, 68.0])
y = np.array([94.92, 94.85, 92.61, 93.44, 94.86, 92.57, 94.88, 93.64, 94.99, 95.40])
plt.plot(x, y, 'b.')
plt.xticks(np.array([0.1, 1, 10, 100]))
plt.xscale('log')
plt.grid(True)
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.