matplotlib.pyplot.subplots
2017-12-14 11:05
489 查看
matplotlib.pyplot.subplots
return:- fig : matplotlib.figure.Figure object
- ax : Axes object or array of Axes objects.
StackOverflow原话:
plt.subplots() is a function that returns a tuple containing a figure and axes object(s). Thus when using fig, ax = plt.subplots() you unpack this tuple into the variables fig and ax. Having fig is useful if you want to change figure-level attributes or save the figure as an image file later (e.g. with fig.savefig(‘yourfilename.png’). You certainly don’t have to use the returned figure object but many people do use it later so it’s common to see. Also, all axes objects (the objects that have plotting methods), have a parent figure object anyway, thus:
fig, ax = plt.subplots()
is more concise than this:
fig = plt.figure()
ax = fig.add_subplot(111)
import tensorflow as tf import numpy as np import matplotlib.pyplot as plt with tf.Session() as sess: # 创建子图 fig, ax = plt.subplots() ax.plot(tf.random_normal([100]).eval(), tf.random_normal([100]).eval(),'o') ax.set_title("Sample random plot for Tensorflow") plt.savefig("result.png") plt.show()
图片自己看吧出不来。
import numpy as np x = np.linspace(0, 2*np.pi,400) y = np.sin(x**2)
"""创建只有一个subplot的fig""" fig, ax = plt.subplots() ax.plot(x, y) ax.set_title('Simple Plot') plt.show()
"""创建两个subplots的fig并解包""" # 子图划分为1行2列 共享Y轴 f, (ax1, ax2) = plt.subplots(1, 2, sharey= True) ax1.plot(x,y) ax1.set_title('Sharing Y axis') ax2.scatter(x, y) plt.show()
"""创建四个极轴,并通过返回的数组访问它们。""" # subplot_kw : Dict with keywords passed to the add_subplot() # add_subplot()的参数polar : If True, equivalent to projection=’polar’. fig, axes = plt.subplots(2,2,subplot_kw=dict(polar=True)) axes[0, 0].plot(x, y) axes[1, 1].scatter(x, y) plt.show()
# 列上共享x轴 plt.subplots(2, 2, sharex='col') #行上共享Y轴 plt.subplots(2, 2, sharey='row') #一个坐标轴上画四个图 plt.subplots(2, 2, sharex='all', sharey='all') #一样效果 plt.subplots(2, 2, sharex=True, sharey=True)
相关文章推荐
- 批量下载matplotlib.pyplot.subplots页面实例源码的python脚本
- matplotlib.pyplot入门
- Python 画多个曲线的折线图(matplotlib.pyplot.plot)
- matplotlib.pyplot.subplot
- Python---matplotlib.pyplot
- from matplotlib import pyplot as plt 报错问题
- matplotlib subplots 设置总图的标题方法
- matplotlib绘图实例:pyplot、pylab模块及作图参数
- matplotlib绘图实例:pyplot、pylab模块及作图参数
- matplotlib基础——pyplot.figure()
- matplotlib基础——matplotlib.pyplot.scatter
- matplotlib.pyplot中add_subplot方法参数111的含义
- 九、matplotlib系列---pyplot极坐标图的绘制
- matplotlib.pyplot.imshow
- python import matplotlib.pyplot 提示找不到DLL
- matplotlib.pyplot基础(二),柱面图,散点图,坐标系填充
- Matplotlib 中文用户指南 3.1 pyplot 教程
- matplotlib.pyplot
- matplotlib.pyplot.subplot
- matplotlib绘图实例:pyplot、pylab模块及作图参