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

Customizing PyLab using style

We will start by importing numpy, matplotlib, and pyplot, as follows:

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

We will also import matplotlib and also import a couple of extra lines to make our plots show up in a proper format:

%matplotlib inline
# Set up figure size and DPI for screen demo
plt.rcParams['figure.figsize'] = (6,4)
plt.rcParams['figure.dpi'] = 150

from scipy.ndimage.filters import gaussian_filter
plt.subplot(221)
plt.text(0.5, 0.5, 'hello')
plt.plot(np.arange(0,1,0.01), np.power(np.arange(0,1,0.01), 3))
plt.ylabel('Axis Label')
plt.subplot(222)
plt.scatter(np.random.normal(size=10), np.random.normal(size=10), c=np.random.normal(size=10))
plt.subplot(223)
plt.hist(np.random.normal(size=1000));
plt.hist(np.random.normal(1, size=1000));
plt.hist(np.random.normal(2, size=500));
plt.ylabel('Axis Label')
plt.xlabel('Axis Label')
plt.subplot(224)
plt.imshow(gaussian_filter(np.random.normal(size=(200,300)), sigma=10))
plt.xlabel('Axis Label')

We will begin with the preceding big block of code and will make an array—a little grid of four plots showing four basic plot types which includes a line plot (top left), a scatter plot (top right), a histogram (bottom left), and an image plot (bottom right), along with the respective axis labels:

By default, Matplotlib will choose some fairly sensible choices for things like fonts, colors, and the other appearance attributes of these plots. These defaults aren't the only choices for appearance attributes that Matplotlib provides.

主站蜘蛛池模板: 丹江口市| 托克逊县| 渑池县| 运城市| 湾仔区| 达尔| 九龙坡区| 嘉善县| 汉中市| 宿松县| 柘荣县| 遵义市| 莱西市| 沂南县| 遵化市| 萍乡市| 韶山市| 松江区| 乌鲁木齐县| 会东县| 商水县| 贵德县| 花垣县| 儋州市| 山阴县| 宜兴市| 电白县| 陆良县| 乌海市| 滁州市| 双流县| 奈曼旗| 黔江区| 汤原县| 保靖县| 舟山市| 柘荣县| 乾安县| 甘孜| 台北市| 莒南县|