在同一轴上绘制2个散点时,奇怪的matplotlib输出

时间:2018-03-01 16:31:57

标签: python pandas matplotlib

我无法弄清楚为什么绘制表现得很奇怪,其他2个函数运行正常。当X_test,y_test是手动输入的数据时,一切似乎都有效,但对于我的特定数据,绘制功能失败,即使它们是正确的形状。 我发布了一个图像的链接,下面的情节结果。 这是通过Jupyter笔记本在Python 3.5上。

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

def draw(X_test, y_test):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(X_test, y_test, c='g', marker='o')  
    ax.scatter(X_test, y_test+5, c='r', marker = '^')
    plt.show()

def drawTest1(X_test, y_test):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(X_test, y_test, c='g', marker='o')  
    plt.show()

def drawTest2(X_test, y_test):
     fig = plt.figure()
     ax = fig.add_subplot(111)
     ax.scatter(X_test, y_test+5, c='r', marker = '^')
     plt.show()

print(X_test.shape, y_test.shape)
drawTest1(X_test, y_test)
drawTest2(X_test, y_test)
draw(X_test, y_test)

the results

编辑:没有字符串,X_test和y_test都是数字

0 个答案:

没有答案