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

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.

主站蜘蛛池模板: 孝义市| 托克逊县| 海淀区| 云阳县| 都兰县| 胶南市| 深州市| 靖边县| 永兴县| 塔河县| 二手房| 荥阳市| 新平| 荆门市| 阳高县| 监利县| 吴桥县| 德阳市| 洪雅县| 明星| 广灵县| 霞浦县| 麻栗坡县| 兖州市| 察雅县| 梁河县| 珠海市| 平凉市| 山西省| 平利县| 灵川县| 平昌县| 澄迈县| 芜湖县| 高安市| 新昌县| 桦南县| 新田县| 泰安市| 平山县| 扎囊县|