How to display legend marks in one with Python 2D plot

A note for Python beginners. Please be careful about mistakes in the content.

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) # set numpoints to 1 plt.show()

if __name__ == '__main__':
    test()

Before:

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

After:

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

Recommended Posts

How to display legend marks in one with Python 2D plot
How to work with BigQuery in Python
How to display multiplication table in python
How to display python Japanese with lolipop
How to display Hello world in python
How to calculate "xx time" in one shot with Python timedelta
[REAPER] How to play with Reascript in Python
How to use tkinter with python in pyenv
How to plot autocorrelation and partial autocorrelation in python
How to convert / restore a string with [] in python
How to do hash calculation with salt in Python
Explain in detail how to make sounds with python
How to do zero-padding in one line with OpenCV
How to run tests in bulk with Python unittest
How to develop in Python
[Python] How to draw a scatter plot with Matplotlib
How to embed multiple embeds in one message with Discord.py
How to check ORM behavior in one file with django
[Ev3dev] How to display bmp image on LCD with python
[Python] How to write an if statement in one sentence.
How to log in to AtCoder with Python and submit automatically
[Python] How to do PCA in Python
Python: How to use async with
How to collect images in Python
How to use SQLite in Python
How to convert 0.5 to 1056964608 in one shot
How to get started with Python
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
How to use FTP with Python
How to use PubChem in Python
How to calculate date with python
How to handle Japanese in Python
How to deal with python installation error in pyenv (BUILD FAILED)
How to not escape Japanese when dealing with json in python
How to create a heatmap with an arbitrary domain in Python
How to use python put in pyenv on macOS with PyCall
Two ways to display multiple graphs in one image with matplotlib
How to display bytes in the same way in Java and Python
[Python, Julia] 3D display in Jupyter-Mayavi library
[Introduction to Python] How to use class in Python?
How to suppress display error in matplotlib
Try logging in to qiita with Python
How to access environment variables in Python
[Python] How to display random numbers (random module)
How to dynamically define variables in Python
How to do R chartr () in Python
[Itertools.permutations] How to put permutations in Python
Display Python 3 in the browser with MAMP
How to extract polygon area in Python
How to use Japanese with NLTK plot
How to do portmanteau test with python
How to check opencv version in python
One liner webServer (with CGI) in python
How to switch python versions in cloud9
How to adjust image contrast in Python
How to use __slots__ in Python class
How to dynamically zero pad in Python
How to enter Japanese with Python curses
To work with timestamp stations in Python