Python中使用相同数据的三个子包

Python中使用相同数据的三个子包,python,pandas,matplotlib,Python,Pandas,Matplotlib,我现在需要一些帮助,因为我是新手。所以我可以分别通过Pandas和Matplotlib导入和绘制我的时间序列数据。问题是,情节太狭窄了(由于lol的数据量) 使用相同的数据集,是否可以将整个地块“划分”为3个独立的子地块 以下是我的意思示例: 我在这里试图做的是将我的图分为3个子图(它似乎没有ncol=x) 最初,我的代码是这样运行的 import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as t

我现在需要一些帮助,因为我是新手。所以我可以分别通过Pandas和Matplotlib导入和绘制我的时间序列数据。问题是,情节太狭窄了(由于lol的数据量)

使用相同的数据集,是否可以将整个地块“划分”为3个独立的子地块

以下是我的意思示例:

我在这里试图做的是将我的图分为3个子图(它似乎没有
ncol=x

最初,我的代码是这样运行的

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

pd.options.display.float_format = '{:,.4f}'.format
data = pd.read_csv ('all_visuallc.csv')   
df = pd.DataFrame(data, columns= ['JD', 'Magnitude'])
print(df) #displays ~37000ish data x 2 columns

colors = ('#696969') #a very nice dim grey heh
area = np.pi*1.7

ax = df.plot.scatter(x="JD", y="Magnitude", s=area, c=colors, alpha=0.2)
ax.set(title='HD 39801', xlabel='Julian Date', ylabel='Visual Magnitude')
ax.invert_yaxis()
ax.xaxis.set_minor_locator(ticker.AutoMinorLocator())
ax.yaxis.set_minor_locator(ticker.AutoMinorLocator())

plt.rcParams['figure.figsize'] = [20, 4]
plt.rcParams['figure.dpi'] = 250
plt.savefig('test_p.jpg')
plt.show()
这显示了一个非常紧凑的图:

谢谢大家,我希望你们的帮助和回应


另一方面,我认为从df中进行切片可能有用。

首先,您必须为数据的每个部分创建多个绘图。 例如,如果我们想将数据分成3个部分,我们将创建3个子部分。然后,正如您正确编写的那样,我们可以对数据应用iloc(或其他类型的索引)

这里是一个玩具的例子,但我希望你能应用你的装饰

y = np.arange(0,20,1)
x = np.arange(20,40,1)
sample = pd.DataFrame(x,y).reset_index().rename(columns={'index':'y', 
0:'x'})

n_plots = 3
figs, axs = plt.subplots(n_plots, figsize=[30,10])
# Suppose we want to split data into equal parts
start_ind = 0
for i in range(n_plots):
    end_ind = start_ind + round(len(sample)/n_plots) #(*)
    part_of_frame = sample.iloc[start_ind:end_ind]
    axs[i].scatter(part_of_frame['x'], part_of_frame['y'])
    start_ind = end_ind


通过更改字符串(*)中的逻辑,也可以将数据拆分为不相等的部分。

对于响应太晚,我深表歉意。尽管如此,它确实有效。:)我有点担心。其中一个子批次(底部)仅包含起点和终点数据。而其余的数据占据了第一和第二个子批次。或者我认为这是因为开始和结束的关系。谢谢你找到了一个bug。请现在测试:)我修复了查找索引的逻辑和舍入方法。现在,如果帧的最后一部分小于圆形(len(frame)/n_图),它将被正确地绘制。好的。我很高兴能帮助你:)