简体   繁体   中英

Evenly space for x-ticks in Matplotlib

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM