Create a plot with 3 subplots histograms with matplotlib and 3 columns of a dataframe
- User
Create a plot with 3 subplots histograms with matplotlib and 3 columns of a dataframe
Assistant
Here is how you can create 3 subplot histograms with matplotlib from 3 columns of a DataFrame:
import matplotlib.pyplot as plt import pandas as pd # Create example DataFrame df = pd.DataFrame({ 'col1': [1,2,3,4,5], 'col2': [2,4,6,8,10], 'col3': [3,6,9,12,15] }) # Set up the figure with 3 subplot axes fig, axes = plt.subplots(1, 3, sharey=True) # Plot histogram for col1 in first subplot df['col1'].plot(kind='hist', ax=axes[0]) # Plot histogram for col2 in second subplot df['col2'].plot(kind='hist', ax=axes[1]) # Plot histogram for col3 in third subplot df['col3'].plot(kind='hist', ax=axes[2]) # Set a common y-label fig.text(0.5, 0.04, 'Values', ha='center', va='center') # Remove x-labels to make space axes[0].set_xlabel('') axes[1].set_xlabel('') # Show the figure plt.show()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.