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

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.

主站蜘蛛池模板: 宜章县| 那坡县| 新干县| 志丹县| 海南省| 石家庄市| 武宁县| 东山县| 孙吴县| 丹凤县| 新乡市| 高平市| 二手房| 陆河县| 双流县| 新余市| 汶川县| 阿克陶县| 仙桃市| 南木林县| 隆林| 西乌| 开远市| 新津县| 锡林郭勒盟| 芜湖市| 酉阳| 丘北县| 三明市| 车致| 金塔县| 长垣县| 出国| 乌拉特中旗| 阳山县| 永兴县| 泊头市| 忻城县| 乐东| 绥中县| 长岭县|