官术网_书友最值得收藏!

  • 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 to do it...

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.

主站蜘蛛池模板: 乌鲁木齐市| 柯坪县| 新宁县| 星座| 济阳县| 额尔古纳市| 隆尧县| 钦州市| 镶黄旗| 田林县| 尚义县| 合肥市| 清远市| 吴旗县| 阿合奇县| 济宁市| 资兴市| 邳州市| 重庆市| 荃湾区| 南川市| 长垣县| 确山县| 枣庄市| 太和县| 灵石县| 怀宁县| 图们市| 芷江| 韩城市| 安仁县| 和林格尔县| 庆云县| 绩溪县| 紫云| 江口县| 明光市| 潞西市| 福建省| 会泽县| 武陟县|