渗压力和温度时间序列数据分析与可视化
渗压力和温度时间序列数据分析与可视化
数据集介绍
本数据集包含了从2021年4月12日至2023年5月31日期间采集的渗压力和温度数据。数据以表格形式呈现,包含以下三列:
- 时间: 数据采集的时间,格式为'yyyy/MM/dd HH:mm'。- 渗压力: 测量的渗压力值。- 温度: 测量温度值,单位为摄氏度(°C)。
数据可视化
为了更好地理解数据趋势和模式,我们使用Java和Apache POI库将数据生成了折线图。以下是代码示例:javapackage 折线图;
import org.apache.poi.ss.usermodel.Cell;import org.apache.poi.ss.usermodel.CellType;import org.apache.poi.ss.util.CellRangeAddress;import org.apache.poi.xddf.usermodel.chart.;import org.apache.poi.xssf.usermodel.;
import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date;
public class ExcelChartExample04 {
public static void main(String[] args) { try { // 读取Excel文件 FileInputStream fileIn = new FileInputStream('input-1.xlsx'); XSSFWorkbook workbook = new XSSFWorkbook(fileIn); XSSFSheet sheet1 = workbook.getSheet('P1');
// 创建折线图 XSSFDrawing drawing = sheet1.createDrawingPatriarch(); XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 129, 10, 149); XDDFChart chart = drawing.createChart(anchor); chart.setTitleText('数据折线图'); chart.setTitleOverlay(false);
// 设置图例位置 XDDFChartLegend legend = chart.getOrAddLegend(); legend.setPosition(LegendPosition.BOTTOM);
// 设置横坐标轴为日期坐标轴 XDDFDataSource<?> dateSource = XDDFDataSourcesFactory.fromNumericCellRange(sheet1, new CellRangeAddress(0, 0, 0, 126)); XDDFDateAxis bottomAxis = chart.createDateAxis(AxisPosition.BOTTOM); bottomAxis.setCrosses(AxisCrosses.AUTO_ZERO); bottomAxis.setTitle('时间'); bottomAxis.setTickLabelPosition(AxisTickLabelPosition.NEXT_TO);
// 设置时间格式 SimpleDateFormat dateFormat = new SimpleDateFormat('yyyy-MM-dd'); for (int i = 0; i < dateSource.getPointCount(); i++) { XSSFRow row = sheet1.getRow(i + 1); if (row != null) { Cell cell = row.getCell(0); if (cell != null && cell.getCellType() == CellType.NUMERIC) { Date date = cell.getDateCellValue(); String formattedDate = dateFormat.format(date); bottomAxis.setTickLabelPosition(AxisTickLabelPosition.NEXT_TO); } } }
// 设置左侧坐标轴为温度坐标轴 XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT); leftAxis.setCrosses(AxisCrosses.AUTO_ZERO); leftAxis.setTitle('温度');
// 设置右侧坐标轴为数值坐标轴 XDDFValueAxis rightAxis = chart.createValueAxis(AxisPosition.RIGHT); rightAxis.setCrosses(AxisCrosses.MAX); rightAxis.setTitle('数据值');
// 设置数据源 XDDFNumericalDataSource<Double> xs1 = XDDFDataSourcesFactory.fromNumericCellRange(sheet1, new CellRangeAddress(1, 127, 0, 0)); XDDFNumericalDataSource<Double> ys1 = XDDFDataSourcesFactory.fromNumericCellRange(sheet1, new CellRangeAddress(1, 127, 2, 2)); // 修正数据列范围
// 添加数据系列 XDDFLineChartData data = (XDDFLineChartData) chart.createData(ChartTypes.LINE, bottomAxis, leftAxis); XDDFLineChartData.Series series1 = (XDDFLineChartData.Series) data.addSeries(xs1, ys1); series1.setTitle('折线图1', null);
// 添加第二个数据系列 (如果需要) // ...
// 将第二个数据系列关联到右侧坐标轴 (如果需要) // ...
// 将数据添加到图表 chart.plot(data);
// 保存Excel文件 FileOutputStream fileOut = new FileOutputStream('input-1.xlsx'); workbook.write(fileOut); fileOut.close();
System.out.println('折线图已创建并保存到Excel文件中。');
} catch (IOException e) { e.printStackTrace(); } }}
代码修改说明:
- 将
ys1的数据源范围修改为(1, 127, 2, 2),以正确读取温度数据列。
数据分析
通过观察生成的折线图,我们可以对渗压力和温度数据进行初步分析,例如:
- 识别数据的趋势和周期性。- 查找异常值和数据突变点。- 分析渗压力和温度之间的相关性。
总结
本文提供的数据集和代码示例可以帮助我们对渗压力和温度数据进行可视化分析。通过进一步的数据挖掘和建模,我们可以更深入地了解数据背后的规律和趋势。
原文地址: https://www.cveoy.top/t/topic/fSwx 著作权归作者所有。请勿转载和采集!