我有以下“标准文件”,用于绘制模拟结果的数据文件:
\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usepackage{siunitx}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale=1]
\begin{axis}[
title=Effect of filter,
minor x tick num =1,
minor y tick num = 2,
anchor=origin,
grid,
xlabel = $ time $ \lbrack \space s \rbrack,
ylabel = $volt$,
ytick={0, 200, ...,1000}]
\addplot [black,very thick] table [x={time}, y={V(pwm)}] {ltspice2.txt};
\addlegendentry{Source Voltage}
\addplot [red,thick] table [x={time}, y={V(n002)}] {ltspice1.txt};
\addlegendentry{Terminal Voltage}
legend pos = north east,
\end{axis}
\end{tikzpicture}
\end{document}
问题是有些数据文件非常大。最新的一个文件包含超过 10 万行。
是否可以让 LaTeX 只读取每第十行?
到目前为止,当我尝试构建整个数据文件时,出现“tex 容量超出”的错误。
答案1
如果有 100,000 个点,我肯定会预处理数据文件并绘制修剪的数据文件。
消除每 10 个点是不够高效的,而且尽管您仍然拥有 10,000 个点,但仍有消除尖峰的风险。
下面是一个示例 Excel 电子表格(xml 格式,应加载到最新版本的 Excel 中),它显示了一种可能粗略但更智能的数据修剪方法。这个想法是想象数据以某个实际像素大小绘制,例如 X 比例超过 1000 像素,Y 比例超过 500 像素。如果下一个数据点与最后一个数据点的像素相同,那么它在绘图中没有任何意义,也可能被拒绝。电子表格只是展示了这个概念。
显然还有其他智能方法(所有数据都在一条线上,你不妨消除中间点等)。但如果你反复点击同一个像素,那你肯定是多余的。
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author>Aubrey Blumsohn</Author>
<LastAuthor>Aubrey Blumsohn</LastAuthor>
<Created>2015-11-15T23:58:16Z</Created>
<LastSaved>2015-11-16T00:09:28Z</LastSaved>
<Version>15.00</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<AllowPNG/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>12135</WindowHeight>
<WindowWidth>25200</WindowWidth>
<WindowTopX>0</WindowTopX>
<WindowTopY>0</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table ss:ExpandedColumnCount="6" ss:ExpandedRowCount="15" x:FullColumns="1"
x:FullRows="1" ss:DefaultRowHeight="15">
<Row>
<Cell><Data ss:Type="String">Xmin</Data></Cell>
<Cell><Data ss:Type="Number">100</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">Xmax</Data></Cell>
<Cell><Data ss:Type="Number">1000</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">Ymin</Data></Cell>
<Cell><Data ss:Type="Number">200</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">Ymax</Data></Cell>
<Cell><Data ss:Type="Number">600</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">PixelsX</Data></Cell>
<Cell><Data ss:Type="Number">1000</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">PixelsY</Data></Cell>
<Cell><Data ss:Type="Number">500</Data></Cell>
</Row>
<Row ss:Index="8">
<Cell><Data ss:Type="String">Data</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="String">X</Data></Cell>
<Cell><Data ss:Type="String">Y</Data></Cell>
<Cell><Data ss:Type="String">PixelX</Data></Cell>
<Cell><Data ss:Type="String">PixelY</Data></Cell>
<Cell><Data ss:Type="String">Eval</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">300</Data></Cell>
<Cell><Data ss:Type="Number">400</Data></Cell>
<Cell ss:Formula="=ROUND(R5C2*(RC[-2]-R1C2)/(R2C2-R1C2),0)"><Data
ss:Type="Number">222</Data></Cell>
<Cell ss:Formula="=ROUND(R6C2*(RC[-2]-R3C2)/(R4C2-R3C2),0)"><Data
ss:Type="Number">250</Data></Cell>
<Cell ss:Formula="=IF(RC[-2]=R[-1]C[-2],IF(R[-1]C[-1]=RC[-1],1,0),0)"><Data
ss:Type="Number">0</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">300.60000000000002</Data></Cell>
<Cell><Data ss:Type="Number">400.2</Data></Cell>
<Cell ss:Formula="=ROUND(R5C2*(RC[-2]-R1C2)/(R2C2-R1C2),0)"><Data
ss:Type="Number">223</Data></Cell>
<Cell ss:Formula="=ROUND(R6C2*(RC[-2]-R3C2)/(R4C2-R3C2),0)"><Data
ss:Type="Number">250</Data></Cell>
<Cell ss:Formula="=IF(RC[-2]=R[-1]C[-2],IF(R[-1]C[-1]=RC[-1],1,0),0)"><Data
ss:Type="Number">0</Data></Cell>
<Cell><Data ss:Type="String">< Reject all data points with a 1 as they would be on the same pixel at chosen scale</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">300.39999999999998</Data></Cell>
<Cell><Data ss:Type="Number">400.1</Data></Cell>
<Cell ss:Formula="=ROUND(R5C2*(RC[-2]-R1C2)/(R2C2-R1C2),0)"><Data
ss:Type="Number">223</Data></Cell>
<Cell ss:Formula="=ROUND(R6C2*(RC[-2]-R3C2)/(R4C2-R3C2),0)"><Data
ss:Type="Number">250</Data></Cell>
<Cell ss:Formula="=IF(RC[-2]=R[-1]C[-2],IF(R[-1]C[-1]=RC[-1],1,0),0)"><Data
ss:Type="Number">1</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">300.3</Data></Cell>
<Cell><Data ss:Type="Number">400.1</Data></Cell>
<Cell ss:Formula="=ROUND(R5C2*(RC[-2]-R1C2)/(R2C2-R1C2),0)"><Data
ss:Type="Number">223</Data></Cell>
<Cell ss:Formula="=ROUND(R6C2*(RC[-2]-R3C2)/(R4C2-R3C2),0)"><Data
ss:Type="Number">250</Data></Cell>
<Cell ss:Formula="=IF(RC[-2]=R[-1]C[-2],IF(R[-1]C[-1]=RC[-1],1,0),0)"><Data
ss:Type="Number">1</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">301</Data></Cell>
<Cell><Data ss:Type="Number">400.5</Data></Cell>
<Cell ss:Formula="=ROUND(R5C2*(RC[-2]-R1C2)/(R2C2-R1C2),0)"><Data
ss:Type="Number">223</Data></Cell>
<Cell ss:Formula="=ROUND(R6C2*(RC[-2]-R3C2)/(R4C2-R3C2),0)"><Data
ss:Type="Number">251</Data></Cell>
<Cell ss:Formula="=IF(RC[-2]=R[-1]C[-2],IF(R[-1]C[-1]=RC[-1],1,0),0)"><Data
ss:Type="Number">0</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">300.60000000000002</Data></Cell>
<Cell><Data ss:Type="Number">400.7</Data></Cell>
<Cell ss:Formula="=ROUND(R5C2*(RC[-2]-R1C2)/(R2C2-R1C2),0)"><Data
ss:Type="Number">223</Data></Cell>
<Cell ss:Formula="=ROUND(R6C2*(RC[-2]-R3C2)/(R4C2-R3C2),0)"><Data
ss:Type="Number">251</Data></Cell>
<Cell ss:Formula="=IF(RC[-2]=R[-1]C[-2],IF(R[-1]C[-1]=RC[-1],1,0),0)"><Data
ss:Type="Number">1</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<Header x:Margin="0.3"/>
<Footer x:Margin="0.3"/>
<PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
</PageSetup>
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>9</ActiveRow>
<ActiveCol>4</ActiveCol>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>