LoginSignup
2
2

More than 5 years have passed since last update.

Python 2D plot で凡例の印を一つに表示する方法

Posted at

Python初心者のメモ。内容の間違いなどご注意ください。

import matplotlib.pyplot as plt
import numpy as np

def test():
    x = np.array([1,2,3,4,5])
    y = np.array([1,2,3,4,5])

    plt.plot(x, y, 'o', label="x and y")
    plt.legend()
    plt.show()

    plt.plot(x, y, 'o', label="x and y")
    plt.legend(numpoints=1) # numpointsを1に設定する
    plt.show()

if __name__ == '__main__':
    test()

Before:

スクリーンショット 2016-03-30 20.05.56.png

After:

スクリーンショット 2016-03-30 20.06.12.png

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2