Package: dream-my-plots
DreamMyPlots 🌜✨🖼️Create plots with LLMs through OpenAI and langchainDreamMyPlots 🌜✨🖼️DreamMyPlots is a friendly utility class for anyone doing data science, who want to turn numbers and data into seaborn/matplot plots quickly, through the power of Python's graph-making skills with any popular LLM prompts (through Langchain)to make even complex charts simple to create.Here's how you can use it:Provide Data📊: Input your DataFrame and what you'd like to visualize.AI Assists🤖: It then uses AI to generate the Python plotting code based on your prompt.Visualize🌟: Run the generated code to see your data transformed into a visual plot.And this may:Saves Time⏰: No need to write complex code from scratch. It's quicker to get your visuals ready.Boosts Creativity🎨: Encourages you to experiment with different types of visuals without the heavy lifting.Simplifies Learning📘: Makes it easier to jump into data visualization, even if you're new to data science.importpandasaspdimportnumpyasnpdf=pd.DataFrame(np.random.rand(100),columns=['A'])🌱 How to Begin💻 Install :pipinstalldream-my-plotsor through github tags,pipinstallgit+https://github.com/mustafah/dream-my-plots.git@1.0.0🔑 Environment variables should contain yourOpenAI(or other LangChain compliantLLM)API key:# Sample .env fileDREAM_MY_PLOTS_LLM_API_KEY=your-key-here📈 Create your dataframe :importpandasaspdimportnumpyasnpdf=pd.DataFrame(np.random.rand(100,3),columns=['A','B','C'])🎨 Dream your plot :fromdream_my_plotsimportDreamMyPlotsDreamMyPlots(df,"""Make line plots for first two columns, and first 7 rows !""")ExamplesComparative Distributions of Two Class Datasets📈 Create your dataframe :importnumpyasnp# Generating features for Class A & B with normal distributionfeatures_class_A=np.random.normal(70,10,100)features_class_B=np.random.normal(80,15,100)features=np.concatenate([features_class_A,features_class_B])# Combining Class A and B featuresclasses=['Class A']*100+['Class B']*100# Creating labels for the classesimportpandasaspddf=pd.DataFrame({'Feature':features,'Class':classes})# Creating DataFrame with features and class labels🌟✍️ Send your prompt :fromdream_my_plotsimportDreamMyPlotsDreamMyPlots(df,"""📊 Make a plot contains 6 kinds of Distribution Plots (Categorical and Continuous Distribution plots)🎨 Give a large title please, fit upto 4 subplots horizontally""")💬✨ More to sayCommentingYou use # character to comment any line in prompt, so it will be not sent to the LLMfromdream_my_plotsimportDreamMyPlotsDreamMyPlots(df,"""📊 Make a plot contains 6 kinds of Distribution Plots (Categorical and Continuous Distribution plots)# 🎨 Give a large title please, fit upto 4 subplots horizontally""")🌑 Dark themeSet an environment with value ofDARKorLIGHTfor the syntax higlightDREAM_MY_PLOTS_THEME=DARKor send it as a parameter in the classfromdream_my_plotsimportDreamMyPlotsDreamMyPlots(df,"""Make a scatter plot !""",dark=True)🔑 API keyYou can pass it directly instead of using .env files (not recommended)fromdream_my_plotsimportDreamMyPlotsDreamMyPlots(df,"""Make a histogram plot !""",api_key="*****")Errors !Try to rexecute your code, as it is or add more specifications to the prompt ... You are last error and generated code is automatically attached when you resend your prompts📝🔧 Custom Prompt Template (🌱 🇦lpha version)fromlangchain.prompts.promptimportPromptTemplatetemplate=PromptTemplate(input_variables=["df","prompt","previous_code","previous_error"],template="your custom template content")fromdream_my_plotsimportDreamMyPlotsDreamMyPlots(df,"""Make a histogram plot !""",prompt="*****",template)💬🔧 Custom LLM (🌱 🇦lpha version)It's based on langchain, you can use your custom llm providerfromlangchain.chat_modelsimportAzureChatOpenAIfromdream_my_plotsimportDreamMyPlotsDreamMyPlots(df,"""Make a histogram plot !""",llm=AzureChatOpenAI(deployment_name="YOUR_DEPLOYMENT_NAME",openai_api_version="2023-05-15",openai_api_key=openai_api_key,...))