如何在matplotlib python中设置x轴值?

时间:2017-06-28 22:36:37

标签: python matplotlib

Graph

我想使用matplotlib绘制此图。我编写了代码,但它没有改变x轴值。

<body>    

    <a id="demo">Hello.</a>

    <script>
       document.getElementById("demo").onclick = function() {
       window.location.href="https://www.google.com"
       };
    </script>

</body>

如何使用matplotlib绘制给定图形的蓝线?

1 个答案:

答案 0 :(得分:13)

示例图上的缩放有点奇怪,但您可以通过绘制每个x值的索引然后将刻度设置为数据点来强制它:

import matplotlib.pyplot as plt
x = [0.00001,0.001,0.01,0.1,0.5,1,5]
# create an index for each tick position
xi = [i for i in range(0, len(x))]
y = [0.945,0.885,0.893,0.9,0.996,1.25,1.19]
plt.ylim(0.8,1.4)
# plot the index for the x-values
plt.plot(xi, y, marker='o', linestyle='--', color='r', label='Square') 
plt.xlabel('x')
plt.ylabel('y') 
plt.xticks(xi, x)
plt.title('compare')
plt.legend() 
plt.show()