簡體   English   中英

掙扎到plot CSV 不同長度的數據集

[英]Struggling to plot CSV data sets of different lengths

我已經從 2 個數據集(CSV 格式)導入了數據,它們分別是 plot。 但是,當我將它們組合起來繪制在同一張圖表上時,我得到了以下錯誤。 如果我刪除 plt.plot(cell_11_cycle1.QQo_mAh / 0.020639, cycle1.Ecell_V) 線,它們 plot 就可以了。 我認為這與數據集的長度有關,有什么方法可以在不操縱原始數據的情況下解決這個問題? 這是我第一次使用 python 進行數據分析。

import pandas as pd
from matplotlib import pyplot as plt

cell_10_cycle0 = Cell_10[Cell_10.cycle_number == 0]
cell_10_cycle1 = Cell_10[Cell_10.cycle_number == 1]
cell_11_cycle0 = Cell_11[Cell_11.cycle_number == 0]
cell_11_cycle1 = Cell_11[Cell_11.cycle_number == 1]

plt.plot(cell_10_cycle0.QQo_mAh / 0.021638, cycle0.Ecell_V)
plt.plot(cell_10_cycle1.QQo_mAh / 0.021638, cycle1.Ecell_V)
plt.plot(cell_11_cycle0.QQo_mAh / 0.020639, cycle0.Ecell_V)
plt.plot(cell_11_cycle1.QQo_mAh / 0.020639, cycle1.Ecell_V)
plt.legend(['Cell 10 Cycle 0', 'Cell 10 Cycle 1', 'Cell 11 Cycle 0', 'Cell 1 Cycle 1'])
plt.xlabel('capacity /mAh/g')
plt.ylabel('Ecell /V')
plt.title('600C Heat Treated Material')

ValueError: x and y must have same first dimension, but have shapes (808,) and (896,)

列 cell_11_cycle1.QQo_mAh 包含 808 個元素,列 cycle1.Ecell_V 包含 896 個元素。 兩列必須具有相同的長度 matplotlib 才能正確 plot 您的數據。 你可以改變:

plt.plot(cell_11_cycle1.QQo_mAh / 0.020639, cycle1.Ecell_V)

至:

plt.plot(cell_11_cycle1.QQo_mAh / 0.020639, cycle1.Ecell_V.iloc[:808])

這僅需要 y 數據的前 808 個元素。 所以你會丟失一部分數據。

更好的選擇似乎是檢查您的數據源,可能缺少一部分 x 值,或者您正在繪制兩個彼此不相關的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM