如何在轴框外显示结果值

时间:2018-04-04 05:28:55

标签: python matplotlib plot

我使用下面的代码绘制了图片。

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(6)

fig = plt.figure()
ax = plt.subplot(111)

for i in xrange(5):
    ax.set_xlim(0, 3)
    ax.set_ylim(0, 10)
    ax.plot(x, i * x)

plt.show()

这是结果图 enter image description here

这是我想看到的图片。
我希望从盒子区域中获得结果 你怎么画这样的情节?

enter image description here

1 个答案:

答案 0 :(得分:1)

这应该有效 -

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(6)

fig = plt.figure()
ax = plt.subplot(111)

for i in xrange(5):
    ax.set_xlim(0, 3)
    ax.set_ylim(0, 10)
    ax.plot(x, i * x)
    if 3*i >10:
        ytx = 10.5
        xtx = 10.0/i
    else:
        ytx = 3*i
        xtx = 3.05
    tx = plt.text(xtx, ytx, str(i), fontsize=18, color='black')

plt.show()

这会生成 -

enter image description here