benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 9a3cbbfc-d430-5a50-bfb9-c864d8520a5c

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import numpy as np
import matplotlib.pyplot as plt
import os


def task_func(mystrings, folder_path, seed=None):
    """
    Generates random data points to plot bar charts for each in a given list of plot names,
    then saves them in a specified directory.

    This function takes a list of plot names, for each generating 10 random data points in [0, 1)
    to create a bar chart, then saves the bar charts as .png files in the specified directory,
    creating the directory if it does not exist.

    Parameters:
    - mystrings (list of str): List of names for the plots.
                               Each is used as the title for each plot, and each is used to derive
                               each plot's filename by replacing spaces with underscores.
    - folder_path (str):       Path of the folder where the plots will be saved.
                               If it does not exist, the function will create it.
    - seed (int, optional):    A seed for the random number generator to ensure reproducible results.
                               Defaults to None.

    Returns:
    - list: Names of the files where the plots are saved. Each file corresponds to a title from `mystrings`.

    Raises:
    - FileNotFoundError: If the provided directory path does not exist and cannot be created.

    Note:
    - This function deduplicates mystrings while maintaining its original order.
    - Random data points for bar charts are generated in the range [0, 1).
    - Each bar chart contains 10 data points.

    Requirements:
    - numpy
    - matplotlib
    - os

    Examples:
    >>> task_func(['Plot 1', 'Plot 2'], './test_images/')
    ['Plot_1.png', 'Plot_2.png']

    >>> task_func(['First Plot', 'Second Plot'], './another_folder/')
    ['First_Plot.png', 'Second_Plot.png']
    """

instruct prompt

Generates random data points to plot bar charts for each in a given list of plot names, then saves them in a specified directory. This function takes a list of plot names, for each generating 10 random data points in [0, 1) to create a bar chart, then saves the bar charts as .png files in the specified directory, creating the directory if it does not exist. >>> task_func(['First Plot', 'Second Plot'], './another_folder/') ['First_Plot.png', 'Second_Plot.png']
Note that: This function deduplicates mystrings while maintaining its original order. Random data points for bar charts are generated in the range [0, 1). Each bar chart contains 10 data points.
The function should raise the exception for: FileNotFoundError: If the provided directory path does not exist and cannot be created.
The function should output with:
    list: Names of the files where the plots are saved. Each file corresponds to a title from `mystrings`.
You should write self-contained code starting with:

Code

import numpy as np
import matplotlib.pyplot as plt
import os
def task_func(mystrings, folder_path, seed=None):

code prompt

Code

import numpy as np
import matplotlib.pyplot as plt
import os
def task_func(mystrings, folder_path, seed=None):

entry point

task_func

libs

  • numpy
  • matplotlib
  • os

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import