- matplotlib Plotting Cookbook
- Alexandre Devert
- 176字
- 2021-07-16 12:16:25
Plotting points
When displaying a curve, we implicitly assume that one point follows another—our data is the time series. Of course, this does not always have to be the case. One point of the data can be independent from the other. A simple way to represent such kind of data is to simply show the points without linking them.
How to do it...
The following script displays 1024 points whose coordinates are drawn randomly from the [0,1] interval:
import numpy as np import matplotlib.pyplot as plt data = np.random.rand(1024, 2) plt.scatter(data[:,0], data[:,1]) plt.show()
The preceding script will produce the following graph:

How it works...
The function plt.scatter()
works exactly like plt.plot()
, taking the x and y coordinates of points as input parameters. However, each point is simply shown with one marker. Don't be fooled by this simplicity—plt.scatter()
is a rich command. By playing with its many optional parameters, we can achieve many different effects. We will cover this in Chapter 2, Customizing the Color and Styles, and Chapter 3, Working with Annotations.
- 數據科學實戰手冊(R+Python)
- JavaScript百煉成仙
- Implementing Modern DevOps
- ReSharper Essentials
- Visual Studio 2012 Cookbook
- Rust實戰
- Mastering Selenium WebDriver
- Unity Shader入門精要
- TradeStation交易應用實踐:量化方法構建贏家策略(原書第2版)
- C#應用程序設計教程
- Mastering AWS Security
- 計算機組裝與維護(第二版)
- Spring Boot學習指南:構建云原生Java和Kotlin應用程序
- 瘋狂Ajax講義(第3版)
- .NET應用架構設計:原則、模式與實踐