简体   繁体   English

Matplotlib 中 x-ticks 的均匀空间

[英]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].我需要绘制这样的图形,其中 x-ticks 在 [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:您可以使用matplotlib.pyplot方法xscale并将“log”作为参数传递:

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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