如何在相同距离的matplot中减少y轴

时间:2019-02-28 11:26:35

标签: matplotlib

我想在38个位置上放置38个,但距离应该相同,我使用了matplot库enter image description here

,图形看起来像是直线峰会消失
# -*- coding: utf-8 -*-
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
s=['05/02/2019', '06/02/2019', '07/02/2019', '08/02/2019', '09/02/2019', '10/02/2019', '11/02/2019', '12/02/2019', '13/02/2019', '20/02/2019', '21/02/2019', '22/02/2019', '23/02/2019', '24/02/2019', '25/02/2019']
df[0]=['38.02'
,'33.79'
,'34.73'
,'36.47'
,'35.03'
,'33.45'
,'33.82'
,'33.38'
,'34.68'
,'36.93'
,'33.44'
,'33.55'
,'33.18'
,'33.07'
,'33.17'
]
# Data for plotting
fig, ax = plt.subplots(figsize=(17, 2))
for i,j in zip(s,df[0]):
    ax.annotate(str(j),xy=(i,j+0.8))
ax.plot(s, df[0])
ax.set(xlabel='Dates', ylabel='Latency',
       title='Hongkong to sing)
ax.grid()
#plt.yticks(np.arange(min(df[p]), max(df[p])+1, 2))
fig.savefig("test.png")
#plt.show()

1 个答案:

答案 0 :(得分:1)

我不能完全确定这是否是您要的内容,但是您可以显式调整y限制以更改比例,即

n!/(k!(n-k)!)

仅设置上限,而下限保持不变,这将为您提供 Y-axis limit control (upper)

您可以提供您认为合适的任何值,即

ax.set_ylim([ax.get_ylim()[0], 42])

会给你一些看起来像 Y-axis limit control (both)

还请注意,情节的刻度标签和外观与此处显示的有所不同。


编辑-以下是要求的完整代码:

ax.set_ylim([22, 52])