python - 如何将结果值显示在轴框之外

标签 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

最佳答案

这应该有效 -

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

关于python - 如何将结果值显示在轴框之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49643430/

相关文章:

python - 如何从上面的行添加 "X"或 "Y"值,而不将不包含 "X"和 "Y"的行读取到缺少该值的行?

r - 在 R 中的 ggmap 对象上绘制 geom_segment - 线未出现

r - 如何使用 grconvertX 在 R 中的任何图中找到中间 x?

java - 在 Android 上创建交互式等高线图

python - 导入错误: DLL load failed: %1 is not a valid Win32 application while importing win32com

python - 如何提高 TensorFlow 中分类、非二元、外语情感分析模型的准确性?

python - 在 Python 中连接到 PostGreSQL 7.3 数据库

python - 使用 matplotlib 的 set_array() 例程的指南是什么?

python - 将 mark_inset 与不同的范围图一起使用

python - 放置一个颜色条 matplotlib