Python 保持matplotlib中两个数据集之间的间距
我有两个数据集Python 保持matplotlib中两个数据集之间的间距,python,matplotlib,Python,Matplotlib,我有两个数据集 firstX = [0, 1, 2, 3, 4, 5, 6] # X Axis firstY = [10, 10, 20, 30, 40, 60, 70] # Y Axis secondX = [9, 10, 11, 12, 13, 14, 15] # X Axis secondY = [40, 20, 60, 11, 77, 12, 54] # Y Axis 我想在同一个图表中绘制这两个数据集,但不将它们连接在一起。如您所见,它们之间存在断开连接(在X轴中,缺少7和8)。当
firstX = [0, 1, 2, 3, 4, 5, 6] # X Axis
firstY = [10, 10, 20, 30, 40, 60, 70] # Y Axis
secondX = [9, 10, 11, 12, 13, 14, 15] # X Axis
secondY = [40, 20, 60, 11, 77, 12, 54] # Y Axis
我想在同一个图表中绘制这两个数据集,但不将它们连接在一起。如您所见,它们之间存在断开连接(在X轴中,缺少7和8)。当我连接它们时,matplotlib将尝试将第一个数据集的最后一点
(6,70)
与第二个数据集的第一点(9,40)
。我想知道如何避免这种行为,而不是连接数据集,您可以调用plot命令两次,在同一轴上打印两次:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(firstX, firstY)
ax.plot(secondX, secondY)
您可以调用plot命令两次,对同一轴打印两次,而不是连接数据集:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(firstX, firstY)
ax.plot(secondX, secondY)
根据我对你问题的理解,这应该是可行的:
import matplotlib.pyplot as plt
plt.figure()
plt.plot(firstX, firstY, c='b')
plt.plot(secondX, secondY, c='b')
plt.show
根据我对你问题的理解,这应该是可行的:
import matplotlib.pyplot as plt
plt.figure()
plt.plot(firstX, firstY, c='b')
plt.plot(secondX, secondY, c='b')
plt.show
您可以单独绘制它们。如果它们是列表的子列表,例如,
X=[[X1],[X2]]
,Y=[[Y1],[Y2]]
,则可以对它们进行循环
import matplotlib.pyplot as plt
fig = plt.figure()
for i in range(len(X)):
plt.plot(X[i], Y[i])
plt.show()
您可以单独绘制它们。如果它们是列表的子列表,例如,
X=[[X1],[X2]]
,Y=[[Y1],[Y2]]
,则可以对它们进行循环
import matplotlib.pyplot as plt
fig = plt.figure()
for i in range(len(X)):
plt.plot(X[i], Y[i])
plt.show()
相关:和相关:和