A chart-to-code supervisory data rewriting method based on observable information alignment
Patent Information
- Application Number
- CN202610983375.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-03
- Publication Date
- 2026-10-09
AI Technical Summary
[0003]本发明为解决现有图表转代码训练存在潜变量监督歧义,无法批量生成图像可约束的监督训练数据的问题,进而提出一种基于可观测信息对齐的图表到代码监督数据改写方法
1.本发明对箱线图、直方图和饼图等绘图API中的隐式聚合过程进行识别与执行抽取,将原始样本、任意尺度数值等潜变量替换为箱线统计、箱级权重、扇区百分比等可见目标。
Smart Images

Figure CN122884464A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a chart-to-code supervised data rewriting method based on observable information alignment, belonging to the field of electronic digital processing technology. Background Technology
[0002] With the development of multimodal models and graph-to-code generation techniques, researchers aim to recover executable plotting programs from graph images to preserve layout, style, and numerical structure, supporting subsequent validation, editing, and reuse. However, existing supervised fine-tuning often treats the reference plotting script as the unique and fully visible gold standard, ignoring the fact that the image cannot uniquely determine all variables in the script. In box plots, the image only presents the median, quartiles, whiskers, and outliers, not the original samples; in pie charts, the image mainly presents sector proportions or percentages, not the original values at arbitrary scales; in histograms, the image presents the mass or height of each bin, not every original observation falling into the bin. Therefore, the closest existing solutions include: one is to continue using the original code / original data array as the supervision target; the other is to improve reconstruction capabilities by expanding the graph code dataset, enhancing post-training targets, or improving execution feedback. While these solutions can improve executability or visual similarity, they still require the model to guess unobservable latent variables, which can easily lead to ambiguity in the supervision target, over-specification, and data illusion, making it difficult to guarantee that the numerical basis in the generated code comes from the image itself. Summary of the Invention
[0003] To address the problem of ambiguity in latent variable supervision in existing graph-to-code training methods and the inability to generate batch image-constrained supervised training data, this invention proposes a graph-to-code supervised data rewriting method based on observable information alignment.
[0004] The technical solution adopted by the present invention to solve the above problems is as follows: The present invention includes the following steps: Step 1: Obtain the original chart drawing code and identify the aggregated drawing API within the original chart drawing code; Step 2: Execute the original chart drawing code, read the intermediate calculation results of the rendered chart object, and extract the observable statistics corresponding to the chart image; Step 3: Replace the unobservable latent variables in the original plotting code with observable statistics, retain the visual style parameters in the original plotting code, and generate observable information aligned with the target code; Step 4: Render the original chart plotting code and the target code that aligns with the observable information respectively, and complete the audit of the rewrite results; Step 5: Align the paired original graph plotting code with the target code and observable information to build a supervised dataset for training a graph-to-code model.
[0005] Furthermore, the aggregated plotting APIs identified in step 1 include box plot interface, histogram interface, and pie chart interface.
[0006] Furthermore, step 2 specifically includes: When the box plot interface is identified, the box plot statistical dictionary containing the median, quartiles, upper and lower boundaries, and outliers is extracted as observable statistics. When the histogram interface is identified, the bin boundaries and bin weights are extracted as observable statistics. When a pie chart interface is identified, the normalized percentage value of the sector is extracted as an observable statistic.
[0007] Furthermore, step 3 specifically includes: The original sample-level plotting interface was replaced with a plotting interface adapted to observable statistics. Synchronously update downstream numerical variables derived from the original data to maintain numerical consistency between subplots; The original code retains all visual style parameters, including color, labels, axes, legends, borders, line widths, and angle controls.
[0008] Furthermore, step 4 specifically includes: Calculate the pixel similarity between two rendered images from different code sources; Distinguish controlled semantic differences arising from normalization, numerical rounding, and latent variable transformations to complete code semantic auditing.
[0009] Furthermore, when the histogram interface is identified, the bin boundaries and bin weight values are extracted as observable statistics, including: normalizing the bin weight values and bin boundaries based on the density switch, stacking mode, coordinate type, and multiple sets of input parameters of the original plotting code.
[0010] Furthermore, when a pie chart interface is identified, the normalized percentage value of the sector is extracted as an observable statistic, including: Normalize the original numerical array to obtain the sector percentage; Match the original sector angle, preserve or reset the percentage display text; For multi-layered pie charts, the values of each layer are normalized independently.
[0011] Furthermore, in step 5, the paired original chart drawing code and the target code aligned with the observable information are constructed into a chart-to-code model training supervised dataset. The supervised dataset is used to fine-tune the visual language model so that the model can learn to directly output box statistics, box weights and sector proportions that can be verified by images without changing the model structure.
[0012] The beneficial effects of this invention are: 1. This invention identifies and extracts implicit aggregation processes in plotting APIs such as box plots, histograms, and pie charts, replacing latent variables such as original samples and arbitrary scale values with visible targets such as box statistics, box weights, and sector percentages.
[0013] 2. This invention generates rewritten executable code while retaining color, label, coordinate axis, legend, direction, and style parameters, thereby reducing the difficulty of model learning and not requiring changes to the model structure. It can be used as a data layer supervision enhancement module to connect different charts to the code model, reduce the generation of unfounded data, and improve the accuracy of restoring the observable numerical structure of the chart.
[0014] 3. This invention replaces irretrievable original samples or arbitrary-scale values with box plot statistics, histogram box weights, and pie chart percentages directly constrained by the rendered image, eliminating latent variable supervision ambiguity at the source. Extraction, dependency propagation, and plotting API replacement rules are designed and implemented for box plots, histograms, and pie charts respectively, generating executable alignment code while preserving the original visual style parameters. This mechanism both protects the visual reproduction target of the charts and avoids the model learning from original data completion without image support.
[0015] 4. This invention verifies the reliability of the rewrite by performing rendering, pixel similarity comparison and semantic difference classification, and uses paired samples for model fine-tuning, thereby improving the observable numerical recovery capability.
[0016] 5. Compared with the prior art, the present invention directly utilizes the executableness of the drawing code and the statistical structure of the rendered object to complete the extraction of observable targets and the minimization of code rewriting in an automated manner, which is lower in cost, more reproducible, and more suitable for building large-scale chart-to-code training data. Attached Figure Description
[0017] Figure 1 This is a flowchart of a graph-to-code supervision data rewriting method based on observable information alignment.
[0018] Figure 2 This is a code execution graph for a graph-to-code supervision data rewriting method based on observable information alignment. Detailed Implementation
[0019] like Figure 1 As shown, the steps of the graph-to-code supervision data rewriting method based on observable information alignment described in this embodiment include: S1: Identify aggregated drawing APIs within the original chart drawing code; Enter the reference plotting code and identify the main aggregate plotting APIs, including boxplot, hist, and pie.
[0020] S2: Execute the original chart plotting code, read the rendered Matplotlib object or intermediate calculation results, extract the visually constrainable observations of each chart type, and complete the target rewriting; The system executes the original script, reads the rendered Matplotlib object or intermediate calculation results, and extracts visually constrainable observations for each chart type. For boxplots, the system generates a statistical dictionary for each bin, containing fields such as med, q1, q3, whislo, whishi, fliers, and necessary fields like cilo, cihi, and mean. It rewrites sample-level boxplot calls into statistical-level bxp calls and synchronously updates bar heights, text, or other downstream variables derived from the original samples, avoiding numerical inconsistencies between different subplots from the same data source. For histograms, the system restores valid bin edges, bincount, bin mass, or density values and constructs weights corresponding to the bin positions. When density=True, stacking, orientation transformation, logarithmic coordinates, or multiple sets of inputs exist, the weights and bin boundaries are normalized according to the original plot semantics, ensuring the rewritten code draws the same bin-level distribution with explicit bins and weights. For pie charts, the system reads the sector ratio corresponding to the original value array and normalizes it into a percentage value; if autopct exists, the displayed text is retained or reset so that the visible percentage is consistent with the sector angle; for nested pie charts or donut charts, normalization is performed independently for each layer.
[0021] S3: Retain the visual control parameters from the original code; The system retains the visual control parameters in the original code, such as color, transparency, border, line width, label, legend, coordinate axis range, direction, start angle, explode, wedgeprops, patch_artist, etc., and only modifies the necessary data definitions and their dependency chains.
[0022] S4: Render the original code and the rewritten code separately, and perform pixel similarity and code semantic auditing; Rendering is performed on both the original and rewritten code separately, and pixel similarity and code semantic auditing are conducted. This audit confirms that the rewrite mainly introduces controlled differences due to normalization, rounding, or transformation from raw data to observables.
[0023] S5: Align the original training samples with observable information to form training data, which is used to fine-tune the visual language model; Finally, the original training samples are aligned with observable information to form training data, which is used to fine-tune the visual language model. This allows the model to learn to directly output box statistics, box weights, and sector proportions that can be verified by images. This training method does not require changes to the model structure and can be used as a data layer supervision enhancement module to integrate different graphs into the code model. The code execution of this invention is as follows: Figure 2 As shown, compared with the prior art, the present invention directly utilizes the executableness of the drawing code and the statistical structure of the rendered object to complete the extraction of observable targets and the minimization of code rewriting in an automated manner. It has lower cost, stronger reproducibility, and is more suitable for building large-scale chart-to-code training data.
[0024] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any way. Although the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the present invention. Any person skilled in the art can make some modifications or alterations to the above-disclosed technical content to create equivalent embodiments without departing from the scope of the present invention. Any simple modifications, equivalent substitutions, and improvements made to the above embodiments without departing from the scope of the present invention, based on the technical essence of the present invention and within the spirit and principles of the present invention, shall still fall within the protection scope of the present invention.
Claims
1. A method for supervising data rewriting from graph to code based on observable information alignment, characterized in that, include: Step 1: Obtain the original chart drawing code and identify the aggregated drawing API within the original chart drawing code; Step 2: Execute the original chart drawing code, read the intermediate calculation results of the rendered chart object, and extract the observable statistics corresponding to the chart image; Step 3: Replace the unobservable latent variables in the original plotting code with observable statistics, retain the visual style parameters in the original plotting code, and generate observable information aligned with the target code; Step 4: Render the original chart drawing code and the target code that aligns with the observable information respectively, and complete the audit of the rewrite result; Step 5: Align the paired original graph plotting code with the target code and observable information to build a supervised dataset for training a graph-to-code model.
2. The graph-to-code supervised data rewriting method based on observable information alignment according to claim 1, characterized in that, The aggregated plotting APIs identified in step 1 include box plot interface, histogram interface, and pie chart interface.
3. The graph-to-code supervised data rewriting method based on observable information alignment according to claim 1, characterized in that, Step 2 specifically includes: When the box plot interface is identified, the box plot statistical dictionary containing the median, quartiles, upper and lower boundaries, and outliers is extracted as observable statistics. When the histogram interface is identified, the bin boundaries and bin weights are extracted as observable statistics. When a pie chart interface is identified, the normalized percentage value of the sector is extracted as an observable statistic.
4. The graph-to-code supervised data rewriting method based on observable information alignment according to claim 1, characterized in that, Step 3 specifically includes: The original sample-level plotting interface was replaced with a plotting interface adapted to observable statistics. Synchronously update downstream numerical variables derived from the original data to maintain numerical consistency between subplots; The original code retains all visual style parameters, including color, labels, axes, legends, borders, line widths, and angle controls.
5. The graph-to-code supervised data rewriting method based on observable information alignment according to claim 1, characterized in that, Step 4 specifically includes: Calculate the pixel similarity between two rendered images from different code sources; Distinguish controlled semantic differences arising from normalization, numerical rounding, and latent variable transformations to complete code semantic auditing.
6. The graph-to-code supervised data rewriting method based on observable information alignment according to claim 3, characterized in that, When the histogram interface is identified, the bin boundaries and bin weight values are extracted as observable statistics, including: normalizing the bin weight values and bin boundaries based on the density switch, stacking mode, coordinate type, and multiple sets of input parameters of the original plotting code.
7. The graph-to-code supervised data rewriting method based on observable information alignment according to claim 3, characterized in that, When a pie chart interface is detected, the normalized percentage values of the sectors are extracted as observable statistics, including: Normalize the original numerical array to obtain the sector percentage; Match the original sector angle, preserve or reset the percentage display text; For multi-layered pie charts, the values of each layer are normalized independently.
8. The graph-to-code supervised data rewriting method based on observable information alignment according to claim 1, characterized in that, In step 5, the paired original graph drawing code is aligned with the target code of the observable information to construct a graph-to-code model training supervised dataset. The supervised dataset is used to fine-tune the visual language model so that the model can learn to directly output box statistics, box weights and sector proportions that can be verified by images without changing the model structure.