样式美化(matplotlib.pyplot.style.use)
2016-12-05 13:59
483 查看
使用matplotlib自带的几种美化样式,就可以很轻松的对生成的图形进行美化。
可以使用matplotlib.pyplot.style.available获取所有的美化样式
使用ggplot进行美化后的结果
可以使用matplotlib.pyplot.style.available获取所有的美化样式
#!/usr/bin/python #coding: utf-8 import numpy as np import matplotlib.pyplot as plt # 获取所有的自带样式 print plt.style.available # 使用自带的样式进行美化 plt.style.use("ggplot") fig, axes = plt.subplots(ncols = 2, nrows = 2) # 四个子图的坐标轴赋予四个对象 ax1, ax2, ax3, ax4 = axes.ravel() x, y = np.random.normal(size = (2, 100)) ax1.plot(x, y, "o") x = np.arange(1, 10) y = np.arange(1, 10) # plt.rcParams['axes.prop_cycle']获取颜色的字典 # 会在这个范围内依次循环 ncolors = len(plt.rcParams['axes.prop_cycle']) # print ncolors # print plt.rcParams['axes.prop_cycle'] shift = np.linspace(1, 20, ncolors) for s in shift: # print s ax2.plot(x, y + s, "-") x = np.arange(5) y1, y2, y3 = np.random.randint(1, 25, size = (3, 5)) width = 0.25 # 柱状图中要显式的指定颜色 ax3.bar(x, y1, width, color = "r") ax3.bar(x + width, y2, width, color = "g") ax3.bar(x + 2 * width, y3, width, color = "y") for i, color in enumerate(plt.rcParams['axes.prop_cycle']): xy = np.random.normal(size= 2) for c in color.values(): ax4.add_patch(plt.Circle(xy, radius = 0.3, color= c)) ax4.axis("equal") plt.show()
使用ggplot进行美化后的结果
相关文章推荐
- python数据分析之(6)简单绘图matplotlib.pyplot
- 在Python的matplotlib.pyplot图表中显示中文
- matplotlib颜色与样式
- matplotlib.pyplot.savefig(*args, **kwargs)保存图片$close()关闭图片
- matplotlib ----- 颜色, 标记样式
- matplotlib-plot-style
- ImportError: No module named matplotlib.pyplot
- Python:matplotlib中pyplot的使用方法
- matplotlib.pyplot.imshow
- matplotlib入门之Pyplot
- arch linux python3.6.2 import matplotlib.pyplot as plt 报错
- matplotlib pyplot 中文显示问题
- matplotlib.pyplot介绍
- Python利用matplotlib.pyplot绘图时如何设置坐标轴刻度
- Python应用matplotlib.pyplot画图总结
- matplotlib.pyplot.subplots
- 浅谈Matplotlib简介和pyplot的简单使用――文本标注和箭头
- matplotlib 可视化 —— 定制画布风格 Customizing plots with style sheets(plt.style)
- python import matplotlib.pyplot 提示找不到DLL
- Python数据可视化利器Matplotlib,绘图入门篇,Pyplot介绍