Skip to content
The Chat Archive
mistral-medium-2505· Mistral AI LMArena Human Preference 140K

How to change size of the plot in matplotlib? I want it wider

  1. User

    How to change size of the plot in matplotlib? I want it wider

  2. Assistant

    To change the size of a plot in Matplotlib, you can use the figsize parameter when creating a figure. The figsize parameter 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 specify figsize:

    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 inches
    

    Notes:

    • The default figsize is (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. 🚀

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.