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

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.

主站蜘蛛池模板: 务川| 景德镇市| 新兴县| 东丰县| 南靖县| 上虞市| 佛学| 永德县| 天峨县| 吴川市| 德清县| 手机| 九龙坡区| 黄浦区| 万全县| 城固县| 老河口市| 滦平县| 淄博市| 文山县| 福建省| 当雄县| 开阳县| 噶尔县| 五常市| 长武县| 鞍山市| 嵊州市| 莆田市| 黎川县| 司法| 林甸县| 海门市| 屏南县| 梅州市| 涟源市| 博罗县| 建瓯市| 庆城县| 沾益县| 丹巴县|