Multiple graphs are displayed in one window (python)

problem

I intend to plot the two graphs in separate windows, but they are overlaid on one window.

Source code

import matplotlib.pyplot as plt
a = [a for a in range(10)]
b = [-a for a in a]
a = plt.plot(a)
b = plt.plot(b)
plt.show()

Execution result

Originally I want to display them in separate windows, but they are drawn as different lines in the same window. Blue line: a data Orange line: b data before.png

Correct writing

If you want to create a new window and draw it, you need to execute plt.figure (). The plt.figure () method is the ability to draw a new window with nothing drawn.

Source code

import matplotlib.pyplot as plt
a = [a for a in range(10)]
b = [-a for a in a]
plt.figure()   #Draw a new window
a = plt.plot(a)
plt.figure()   #Draw a new window
b = plt.plot(b)
plt.show()

Execution result

It is divided into two windows and displayed. Above graph: a data Bottom graph: b data after_1.png after_2.png

Recommended Posts

Multiple graphs are displayed in one window (python)
Handle multiple python versions in one jupyter
One liner in Python
Multiple regression expressions in Python
Fizzbuzz in Python (in one line)
DMD in Python one dimension
Avoid multiple loops in Python
Prohibit multiple launches in python
For those who are having trouble drawing graphs in python
[Python] Show multiple windows in Tkinter
Make python segfault in one line
Statistical test (multiple test) in Python: scikit_posthocs
Use OpenCV with Python 3 in Window
Delete multiple elements in python list
[Python] [3D line graph] Multiple data in one graph, axis values in characters
Two ways to display multiple graphs in one image with matplotlib
When specifying multiple keys in python sort
New in Python 3.9 (2)-Sort directed acyclic graphs in Python
CGI server (1) python edition in one line
Modules and packages in Python are "namespaces"
Line graphs and scale lines in python
Send email to multiple recipients in Python (Python 3)
Process multiple lists with for in Python
How to write a string when there are multiple lines in python
Decompose command arguments in one line in Python
[Python] Combine multiple Excel sheets into one
[Python] Invert bool value in one line
Combine multiple python files into one python file
Execution order when multiple context managers are specified in the Python with statement
One liner that outputs multiplication tables in Python
Check if the characters are similar in Python
Try implementing two stacks in one array in Python
Save multiple models in one form with Django
Connect multiple videos in one shot using OpenCV!
[Python & Unix] Combine multiple PDF files into one.
I want to create a window in Python
One liner to 100% CPU1 core usage in Python
[Python] How to draw multiple graphs with Matplotlib
Get multiple maximum keys in Python dictionary type
Draw graphs in Julia ... Leave the graphs to Python
Get the X Window System window title in Python
[Python] Ravel () is convenient when drawing multiple graphs
[Python] Dealing with multiple call errors in ray.init
The one that displays the progress bar in Python
Why you are interested in motor control in Python
[python] ERROR: Python headers are missing in /usr/include/python3.X m.
Sample to put Python Kivy in one file
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python