Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用不同的轴类型打印多个打印_Python_Python 3.x_Matplotlib_Python 2.7 - Fatal编程技术网

Python 使用不同的轴类型打印多个打印

Python 使用不同的轴类型打印多个打印,python,python-3.x,matplotlib,python-2.7,Python,Python 3.x,Matplotlib,Python 2.7,我有下面的代码,但我希望它们在同一个图上,但不同的子图 创建不同轴的最简单方法是什么 from pylab import * figure(0) x =1 y = 2 plot(x, y, marker ='^', linewidth=4.0) xlabel('time (s)') ylabel('cost ($)') title('cost vs. time') figure(1) x = 4 y = 100 plot(x, y, marker ='^', linewidth=4.0)

我有下面的代码,但我希望它们在同一个图上,但不同的子图

创建不同轴的最简单方法是什么

from pylab import *

figure(0)
x =1
y = 2
plot(x, y, marker ='^', linewidth=4.0)
xlabel('time (s)')
ylabel('cost ($)')
title('cost vs. time')

figure(1)

x = 4
y = 100
plot(x, y, marker ='^', linewidth=4.0)
xlabel('cost ($)')
ylabel('performance (miles/hr) ')
title('cost vs. time')


show()

您可以使用
pyplot.subplot
。我正在使用建议用于编程的
pyplot
api(请参阅:)


太棒了,但是给这些子批次贴上标签并给每个子批次指定一个特定标题的命令是什么呢。。。谢谢
import matplotlib.pyplot as plt

fig, (ax0, ax1) = plt.subplots(ncols=2)
x = 1
y = 2
ax0.plot(x, y, marker ='^')
ax0.set_xlabel('time (s)')
ax0.set_ylabel('cost ($)')
ax0.set_title('Plot 1')

x = 4
y = 100
ax1.plot(x, y, marker ='^')
ax1.set_xlabel('cost ($)')
ax1.set_ylabel('performance (miles/hr)')
ax1.set_title('Plot 2')

fig.suptitle('cost vs. time')
plt.subplots_adjust(top=0.85, bottom=0.1, wspace=0.25)
plt.show()