绘制两个不同大小的不同数据帧?

时间:2016-11-21 20:16:38

标签: python matplotlib

我有问题绘制两个数据帧。一个有20711个条目,另一个是20710个条目。我正在使用plot(x,y)来绘制这样的图片:

$.widget( "custom.iconselectmenu", $.ui.selectmenu, {
_renderItem: function( ul, item ) {
    var li = $( "<li>", { text: item.label } );

    if ( item.disabled ) {
        li.addClass( "ui-state-disabled" );
    }

    $( "<span>", {
        style: item.element.attr( "data-style" ),
        "class": "ui-icon " + item.element.attr( "data-class" )
    })
    .appendTo( li );

    return li.appendTo( ul );
},});      
$("#filesA").iconselectmenu({ change: function( event, ui ) { alert("Hi"); s}}).iconselectmenu( "menuWidget" ).addClass( "ui-menu-icons" );

两者都是从csv中提取的数据帧。有这种结构:

import pandas as pd
import csv
import matplotlib.pyplot as plt

fig1 = plt.figure(figsize= (10,10))
ax = fig1.add_subplot(111)
ax.plot(X, Y)

我一直收到错误:

print(X)
0        -2.343060
1        -2.445431
2        -2.335754
3        -2.478535
4        -2.527026
print(Y)
0        0.026940
1       -0.075431
2        0.024246
3       -0.118535
4       -0.167026
5       -0.145475

如何修复它以忽略最后一个条目?

1 个答案:

答案 0 :(得分:0)

如果您可以抛弃Y的最后一个值,那么以下内容应该可以正常工作,假设您的数据框中也有索引,也就是说,您的csv看起来像这样:

0,-2.343060
1,-2.445431
2,-2.335754
3,-2.478535
4,-2.527026

你加载了X=pandas.read_csv('x.csv'),然后

ax.plot(X.as_matrix().T[1], Y.as_matrix().T[1][:-1])

应该有用。

正如您在评论中提到的,重叠有所不同:

ax.plot(X.as_matrix().T[1], Y.as_matrix().T[1][:len(x)])
相关问题