Grafici e diagrammi
In questa pagina
Analisi dei dati visivi
Grafici, diagrammi e tabelle sono onnipresenti nel mondo professionale: report finanziari, dashboard, presentazioni, pubblicazioni scientifiche. Grok Vision ti permette di estrarre automaticamente dati e insight da questi elementi visivi.
Perché è diverso dall’OCR
L’analisi dei grafici va ben oltre la semplice estrazione del testo. Il modello deve:
- Identificare il tipo di grafico (a barre, a linee, a torta, a dispersione, ecc.)
- Leggere gli assi e le relative scale
- Estrarre i valori dei dati
- Comprendere le legende e associarle alle serie di dati
- Interpretare tendenze e pattern
Analisi di un grafico semplice
def analyze_chart(image_url):
prompt = """Analyze this chart and provide:
1. Chart type (bar, line, pie, etc.)
2. Chart title (if visible)
3. X and Y axis labels
4. Extracted data as a table
5. Main observed trend
6. Any annotations or notable points
Present the data in a markdown table."""
response = client.responses.create(
model="grok-4.5",
input=[
{"type": "input_image", "image_url": image_url, "detail": "high"},
{"type": "input_text", "text": prompt}
],
store=False
)
return response.output_text
La modalità detail: "high" è essenziale per leggere con precisione i valori sugli assi e nelle legende.
Estrazione di dati tabellari
Per ottenere dati pronti all’uso diretto nel tuo codice:
def extract_chart_data(image_url):
prompt = """Extract data from this chart in JSON.
Expected format:
{
"type": "bar|line|pie|scatter",
"title": "...",
"x_axis": {"label": "...", "values": [...]},
"y_axis": {"label": "...", "unit": "..."},
"series": [
{
"name": "Series 1",
"values": [10, 20, 30, ...]
}
]
}
Estimate numerical values as precisely as possible
based on the position of points/bars relative
to the tick marks."""
response = client.responses.create(
model="grok-4.5",
input=[
{"type": "input_image", "image_url": image_url, "detail": "high"},
{"type": "input_text", "text": prompt}
],
store=False
)
return response.output_text
Analisi di diagrammi tecnici
Grok gestisce efficacemente anche diagrammi di architettura, flowchart e schemi di flusso:
def analyze_diagram(image_url):
prompt = """Analyze this technical diagram and describe:
1. Diagram type (architecture, flow, flowchart, UML, etc.)
2. Main components/entities
3. Connections and relationships between components
4. Data or process flow (if applicable)
5. Technologies or tools mentioned
If this is a flow diagram, describe the main path
from end to end."""
response = client.responses.create(
model="grok-4.5",
input=[
{"type": "input_image", "image_url": image_url, "detail": "high"},
{"type": "input_text", "text": prompt}
],
store=False
)
return response.output_text
Confronto tra grafici
Puoi inviare più grafici nella stessa richiesta per un’analisi comparativa:
def compare_charts(url_chart_1, url_chart_2):
prompt = """Compare these two charts and identify:
1. Common points (measured variables, period, etc.)
2. Differences in trend
3. Significant gaps
4. A 3-4 sentence summary"""
response = client.responses.create(
model="grok-4.5",
input=[
{"type": "input_text", "text": "Chart 1:"},
{"type": "input_image", "image_url": url_chart_1, "detail": "high"},
{"type": "input_text", "text": "Chart 2:"},
{"type": "input_image", "image_url": url_chart_2, "detail": "high"},
{"type": "input_text", "text": prompt}
],
store=False
)
return response.output_text
Caso d’uso professionale: report automatizzati
Immagina una pipeline che trasforma screenshot di dashboard in report testuali:
def generate_dashboard_report(screenshots):
report_sections = []
for i, screenshot in enumerate(screenshots, 1):
prompt = f"""You are a business analyst. This screenshot
is section {i} of a dashboard. Analyze the displayed metrics
and write a professional summary paragraph.
Include:
- Main KPIs and their values
- Trends (increase, decrease, stability)
- Visible alerts or anomalies
- A recommendation if relevant"""
response = client.responses.create(
model="grok-4.5",
input=[
{"type": "input_image", "image_url": screenshot, "detail": "high"},
{"type": "input_text", "text": prompt}
],
store=False
)
report_sections.append(response.output_text)
return "\n\n".join(report_sections)
Limiti dell’analisi dei grafici
- Precisione dei valori: Grok stima i valori in base alla posizione visiva. Per valori esatti, preferisci i dati sorgente
- Grafici 3D: Le rappresentazioni in prospettiva complicano la lettura dei valori
- Grafici sovrapposti: Quando più serie si sovrappongono, la distinzione può risultare difficile
- Legende piccole: Le leggende con testo molto piccolo potrebbero essere lette male anche in modalità
high
Punti chiave
- Grok analizza i grafici comprendendo il contesto, non solo il testo
- Usa
detail: "high"per una lettura precisa di valori e legende - Richiedi un formato strutturato (JSON, tabella markdown) per sfruttare i dati
- Il confronto multi-immagine funziona bene per le analisi incrociate
- I valori estratti sono stime visive, non dati esatti