A simple AI-powered tool to generate Matplotlib plots using natural language prompts.
PlotLM is a Streamlit-based web application that leverages AI to generate Python Matplotlib plots from user descriptions. It uses the DeepSeek-R1 model via Ollama to generate fully functional, high-quality Python code for data visualization.
This project serves as a proof of concept. While it is functional, it is built such that the code generated by the underlying LLM model is directly executed to create the requested plots. Therefore, it should not be deployed on a public endpoint in its current state as it is vulnerable to prompt engineering attacks.
✅ AI-Powered Plot Generation – Describe the plot, and AI writes the Matplotlib code for you.
✅ Live Code Execution – The app runs the generated code and displays the plot instantly.
✅ Code Transparency – View and copy the generated Python code for further customization.
✅ Multiple AI Models – Choose from different DeepSeek-R1 models based on hardware capabilities. For good results, at least the 14b parameter model should be used as smaller models sometimes suffer from code flaws.
Prompt: Generate a scatterplot with 100 randomly sampled points within [0,1][0,1]
Prompt: Sample 50 points from f(x) = x and add some normally distributed noise to them. Then plot them together with the least squares regression line for these points
Prompt: Visualize the normal distribution
Prompt: Create a 3d plot of 50 points randomly sampled using cosine weighted hemisphere sampling.
Ensure you have the following installed on your system:
- Tested on Python 3.10.16
- Pip (Python Package Manager), use of environment manager is reccomended
- Ollama (AI Model Service) – Install from Ollama's official website.
git clone https://github.com/SvenPfiffner/PlotLLM.git
cd PlotLLMpython -m venv venvpip install -r requirements.txtMake sure Ollama is running before starting the app:
ollama serveThen, start PlotLLM:
streamlit run ui.py- Open the PlotLLM web interface in your browser.
- Describe the plot you want (e.g., "Generate a bar chart for sales data of 3 products.").
- Select an AI model from the sidebar.
- View the generated Python code and the rendered plot.
- Copy the code for further use or modifications.
Note: I will not have the time to develop this project further than the proof-of-concept phase atm. However, contributions are more than welcome.
- Improve security to prevent arbitrary code execution.
- Add an option for users to upload datasets for plotting.
- ...
Contributions are welcome! Here’s how you can help:
- Fork the Repository
- Create a Feature Branch (
git checkout -b feature-branch) - Commit Your Changes (
git commit -m "Add a new feature") - Push to Your Branch (
git push origin feature-branch) - Create a Pull Request
This project is licensed under the MIT License. See LICENSE for details.
- DeepSeek-R1 – AI model used for reasoning.
- Ollama – AI service used for running DeepSeek models.
- Streamlit – Web framework for the UI.



