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

How to use styles to change the appearance of our plots

By using the style module within pyplot, you can see that when we call the function available, we actually get a list containing a number of different styles. Let's assume that each of these different styles acts to change the attributes and the appearance of the plots:

So, by using the plot.style.use method, we can load up any one of these default style sheets. Using the ggplot (as shown in the preceding output) will actually mimic the appearance of the ggplot library, as you can see in the following code:

# Using styles
plt.style.use('dark_background')
from scipy.ndimage.filters import gaussian_filter
plt.subplot(221)
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')

After calling the plt.style.use('ggplot') method, we have the same kind of plots shown, but the axis objects and the appearance of these has been changed fairly significantly. There exists a white grid on a gray background, the fonts have changed as well as their colors, and the default color choices have changed as well.

Hence, we see that the histogram will have different colors, as shown in the following output:

We can also change this to any other choice as well. If you're familiar with the Seaborn library, a Python library for doing more complicated analysis statistically, you can choose options that will mimic the Seaborn library:

# Using styles
plt.style.use('seaborn-talk')
from scipy.ndimage.filters import gaussian_filter
plt.subplot(221)
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')
主站蜘蛛池模板: 赤水市| 金阳县| 阿克陶县| 闵行区| 新泰市| 湘乡市| 思茅市| 乌拉特中旗| 广德县| 安丘市| 山东| 甘谷县| 杭州市| 忻城县| 西峡县| 清河县| 理塘县| 怀安县| 蒲江县| 青龙| 太谷县| 乌拉特前旗| 洛南县| 池州市| 赤城县| 姜堰市| 博罗县| 汉中市| 阿拉善左旗| 嘉黎县| 和平区| 孟连| 隆林| 萝北县| 深圳市| 仁化县| 杭锦旗| 宁蒗| 定州市| 政和县| 南江县|