I’m having trouble with chart visualization when working with Langchain CSV agents in VS Code. The same code works perfectly in Jupyter notebooks and shows all the plots I need, but when I switch to VS Code, the charts just don’t appear at all.
The weird thing is that VS Code runs the code without any errors and gives me text responses as expected. It’s just the visual plots that are missing. I’ve tried different types of charts but none show up in VS Code.
Here’s my code:
from langchain.agents import create_csv_agent
from langchain.llms import OpenAI
import os
import pandas as pd
os.environ["OPENAI_API_KEY"] = "your-api-key-here"
csv_agent = create_csv_agent(
OpenAI(temperature=0.3),
"sales_data.csv",
verbose=True
)
result = csv_agent.run("Create a bar chart showing the distribution of purchase methods")
Has anyone experienced this issue before? I’m wondering if there’s a specific configuration needed for VS Code to display plots generated by Langchain agents. Any help would be appreciated!
Been there. Langchain’s CSV agent creates plots internally but can’t display them properly in VS Code.
What worked for me: explicitly tell the agent to save plots instead of displaying them. Change your prompt to “Create a bar chart showing the distribution of purchase methods and save it as purchase_methods.png”.
Or intercept the plotting with a custom function before running the agent:
import matplotlib
matplotlib.use('Agg') # Use non-interactive backend
import matplotlib.pyplot as plt
# Your langchain code here
result = csv_agent.run("Create a bar chart and save as chart.png")
This forces matplotlib to save files instead of trying to display them in a window VS Code won’t show.
I picked up this debugging trick from watching how others handle data visualization in different environments:
The video covers similar display issues with data structures in VS Code. Really helped me understand why some things work in Jupyter but fail elsewhere.
install the python extension for vs code if u don’t have it yet. also, grab the jupyter extension - vs code sometimes needs both to show plots properly. I had the same problem and adding ‘%matplotlib inline’ at the top solved it, even though I wasn’t using jupyter.
It seems like you’re running into a common issue with the matplotlib backend in VS Code. Unlike Jupyter, VS Code doesn’t automatically display plots generated by Langchain’s CSV agent. To resolve this, you can add ‘import matplotlib.pyplot as plt’ and then call ‘plt.ion()’ at the beginning of your script to enable interactive mode. Also, make sure to use ‘plt.show()’ after your agent’s run command to display the chart. Additionally, setting the MPLBACKEND environment variable to ‘TkAgg’ or ‘Qt5Agg’ can be helpful; I’ve found that ‘TkAgg’ works well on various systems. This should allow your charts to appear in separate windows, improving visibility.
Spent weeks banging my head against this wall before figuring it out. The problem isn’t matplotlib backends or VS Code extensions - it’s that Langchain’s CSV agent creates plots but can’t handle VS Code’s output system properly. I checked the agent’s execution logs and saw it was making the plots but failing silently when trying to display them. Fixed it by setting matplotlib to use a GUI backend explicitly with matplotlib.use('TkAgg') before importing anything else. Also super important: make sure your VS Code Python interpreter matches where you installed langchain and matplotlib. I was using a different Python path which screwed up rendering. After fixing the interpreter path and forcing TkAgg backend, charts started popping up in separate windows like they should.
Yeah, this happens when VS Code’s plot backend isn’t set up right. But honestly? Skip the environment setup nightmare.
I’ve been using Latenode to automate CSV visualization stuff like this. Instead of fighting with VS Code configs, just build a flow that processes your CSV, makes the charts, and sends them wherever you need.
I usually create a scenario that takes the CSV, runs analysis, generates plots with proper libraries, then saves or displays results. Works the same way every time - no IDE headaches.
Best part? You can schedule these to run automatically or trigger via webhook. No more jumping between Jupyter and VS Code just to see charts.