mistral-medium-2505· Mistral AI LMArena Human Preference 140K
How to change size of the plot in matplotlib? I want it wider
- User
How to change size of the plot in matplotlib? I want it wider
- Assistant
To change the size of a plot in Matplotlib, you can use the
figsizeparameter when creating a figure. Thefigsizeparameter takes a tuple of(width, height)in inches.Example: Making a Plot Wider
import matplotlib.pyplot as plt # Create a figure with a wider size (e.g., 10 inches wide, 5 inches tall) plt.figure(figsize=(10, 5)) # Plot something (example) plt.plot([1, 2, 3, 4], [1, 4, 9, 16]) plt.title("Wider Plot Example") plt.xlabel("X-axis") plt.ylabel("Y-axis") plt.show()Alternative: Using
subplots()If you're using
plt.subplots(), you can also specifyfigsize:fig, ax = plt.subplots(figsize=(12, 4)) # 12 inches wide, 4 inches tall ax.plot([1, 2, 3, 4], [1, 4, 9, 16]) plt.show()Adjusting After Creation
If you already have a figure and want to resize it later:
fig = plt.gcf() # Get current figure fig.set_size_inches(10, 5) # Resize to 10x5 inchesNotes:
- The default
figsizeis(6.4, 4.8)inches. - You can also adjust the DPI (dots per inch) for higher resolution:
plt.figure(figsize=(10, 5), dpi=100) # Higher DPI for better quality
This will make your plot wider while keeping the height proportional or fixed as needed. 🚀
- The default
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.