This example plots sine and cosine curves in a Google Colab notebook with Python, NumPy, and Matplotlib. Colab’s interface and menu labels can change, so create a blank notebook using the current interface.
Requirements
You need a Google Account and an internet connection. With Colab’s hosted runtime, you can run the code without setting up a local Python environment.
Run the notebook cell
Paste the code into a code cell in a new notebook and run the cell. x contains 500 evenly spaced values from 0 through 2π. The plot evaluates sine and cosine at those radian values and displays a legend.
| |
Example result
The cell displays a graph with the sine and cosine curves. If a library is unavailable in the hosted runtime, run %pip install numpy matplotlib in a cell, then rerun the example.


