prompt
stringlengths
105
757
reference_code
stringlengths
12
387
code_context
stringlengths
1.3k
3.36k
problem_id
int64
511
665
library_problem_id
int64
0
154
library
stringclasses
1 value
test_case_cnt
int64
1
1
perturbation_type
stringclasses
2 values
perturbation_origin_id
int64
0
154
user_chat_prompt
stringlengths
512
1.16k
test_code
stringlengths
974
2.48k
solution_function
stringlengths
212
1.29k
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Make a scatter plot with x and y and set marker size to be 100 # Combine star hatch and vertical line hatch together for the marker # SOLUTION START
plt.scatter(x, y, hatch="*|", s=500)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.scatter(x, y, hatch="*|", s=500) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.collections[0].get_sizes()[0] == 500 assert ax.collections[0].get_hatch() is not None assert "*" in ax.collections[0].get_hatch() assert "|" in ax.collections[0].get_hatch() return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
612
101
Matplotlib
1
Semantic
98
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Make a scatter plot with x and y and set marker size to be 100 - Combine star hatch and vertical line hatch together for the marker - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.scatter(x, y, hatch="*|", s=500) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.collections[0].get_sizes()[0] == 500 assert ax.collections[0].get_hatch() is not None assert "*" in ax.collections[0].get_hatch() assert "|" in ax.collections[0].get_hatch() return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.scatter(x, y, hatch="*|", s=500) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt import numpy as np data = np.random.random((10, 10)) # Set xlim and ylim to be between 0 and 10 # Plot a heatmap of data in the rectangle where right is 5, left is 1, bottom is 1, and top is 4. # SOLUTION START
plt.xlim(0, 10) plt.ylim(0, 10) plt.imshow(data, extent=[1, 5, 1, 4])
import matplotlib.pyplot as plt import numpy as np from PIL import Image import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): data = np.random.random((10, 10)) plt.xlim(0, 10) plt.ylim(0, 10) plt.imshow(data, extent=[1, 5, 1, 4]) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: for c in plt.gca().get_children(): if isinstance(c, matplotlib.image.AxesImage): break assert c.get_extent() == [1, 5, 1, 4] return 1 exec_context = r""" import matplotlib.pyplot as plt import numpy as np data = np.random.random((10, 10)) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
613
102
Matplotlib
1
Origin
102
Given this code block: ``` import matplotlib.pyplot as plt import numpy as np data = np.random.random((10, 10)) ``` Please help me to: - Set xlim and ylim to be between 0 and 10 - Plot a heatmap of data in the rectangle where right is 5, left is 1, bottom is 1, and top is 4. - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt import numpy as np from PIL import Image import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): data = np.random.random((10, 10)) plt.xlim(0, 10) plt.ylim(0, 10) plt.imshow(data, extent=[1, 5, 1, 4]) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: for c in plt.gca().get_children(): if isinstance(c, matplotlib.image.AxesImage): break assert c.get_extent() == [1, 5, 1, 4] return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt import numpy as np data = np.random.random((10, 10)) plt.xlim(0, 10) plt.ylim(0, 10) plt.imshow(data, extent=[1, 5, 1, 4]) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0.1, 2 * np.pi, 41) y = np.exp(np.sin(x)) # make a stem plot of y over x and set the orientation to be horizontal # SOLUTION START
plt.stem(x, y, orientation="horizontal")
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.linspace(0.1, 2 * np.pi, 41) y = np.exp(np.sin(x)) plt.stem(x, y, orientation="horizontal") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.collections) == 1 for seg in ax.collections[0].get_segments(): assert seg[0][0] == 0 return 1 exec_context = r""" import matplotlib.pyplot as plt import numpy as np x = np.linspace(0.1, 2 * np.pi, 41) y = np.exp(np.sin(x)) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
614
103
Matplotlib
1
Origin
103
Given this code block: ``` import matplotlib.pyplot as plt import numpy as np x = np.linspace(0.1, 2 * np.pi, 41) y = np.exp(np.sin(x)) ``` Please help me to: - make a stem plot of y over x and set the orientation to be horizontal - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.linspace(0.1, 2 * np.pi, 41) y = np.exp(np.sin(x)) plt.stem(x, y, orientation="horizontal") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.collections) == 1 for seg in ax.collections[0].get_segments(): assert seg[0][0] == 0 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt import numpy as np x = np.linspace(0.1, 2 * np.pi, 41) y = np.exp(np.sin(x)) plt.stem(x, y, orientation="horizontal") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt d = {"a": 4, "b": 5, "c": 7} c = {"a": "red", "c": "green", "b": "blue"} # Make a bar plot using data in `d`. Use the keys as x axis labels and the values as the bar heights. # Color each bar in the plot by looking up the color in colors # SOLUTION START
colors = [] for k in d: colors.append(c[k]) plt.bar(range(len(d)), d.values(), color=colors) plt.xticks(range(len(d)), d.keys())
import matplotlib.pyplot as plt from PIL import Image import numpy as np import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): d = {"a": 4, "b": 5, "c": 7} c = {"a": "red", "c": "green", "b": "blue"} colors = [] for k in d: colors.append(c[k]) plt.bar(range(len(d)), d.values(), color=colors) plt.xticks(range(len(d)), d.keys()) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() plt.show() count = 0 x_to_color = dict() for rec in ax.get_children(): if isinstance(rec, matplotlib.patches.Rectangle): count += 1 x_to_color[rec.get_x() + rec.get_width() / 2] = rec.get_facecolor() label_to_x = dict() for label in ax.get_xticklabels(): label_to_x[label._text] = label._x assert ( x_to_color[label_to_x["a"]] == (1.0, 0.0, 0.0, 1.0) or x_to_color[label_to_x["a"]] == "red" ) assert ( x_to_color[label_to_x["b"]] == (0.0, 0.0, 1.0, 1.0) or x_to_color[label_to_x["a"]] == "blue" ) assert ( x_to_color[label_to_x["c"]] == (0.0, 0.5019607843137255, 0.0, 1.0) or x_to_color[label_to_x["a"]] == "green" ) return 1 exec_context = r""" import matplotlib.pyplot as plt d = {"a": 4, "b": 5, "c": 7} c = {"a": "red", "c": "green", "b": "blue"} [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
615
104
Matplotlib
1
Origin
104
Given this code block: ``` import matplotlib.pyplot as plt d = {"a": 4, "b": 5, "c": 7} c = {"a": "red", "c": "green", "b": "blue"} ``` Please help me to: - Make a bar plot using data in `d`. Use the keys as x axis labels and the values as the bar heights. - Color each bar in the plot by looking up the color in colors - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt from PIL import Image import numpy as np import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): d = {"a": 4, "b": 5, "c": 7} c = {"a": "red", "c": "green", "b": "blue"} colors = [] for k in d: colors.append(c[k]) plt.bar(range(len(d)), d.values(), color=colors) plt.xticks(range(len(d)), d.keys()) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() plt.show() count = 0 x_to_color = dict() for rec in ax.get_children(): if isinstance(rec, matplotlib.patches.Rectangle): count += 1 x_to_color[rec.get_x() + rec.get_width() / 2] = rec.get_facecolor() label_to_x = dict() for label in ax.get_xticklabels(): label_to_x[label._text] = label._x assert ( x_to_color[label_to_x["a"]] == (1.0, 0.0, 0.0, 1.0) or x_to_color[label_to_x["a"]] == "red" ) assert ( x_to_color[label_to_x["b"]] == (0.0, 0.0, 1.0, 1.0) or x_to_color[label_to_x["a"]] == "blue" ) assert ( x_to_color[label_to_x["c"]] == (0.0, 0.5019607843137255, 0.0, 1.0) or x_to_color[label_to_x["a"]] == "green" ) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt d = {"a": 4, "b": 5, "c": 7} c = {"a": "red", "c": "green", "b": "blue"} colors = [] for k in d: colors.append(c[k]) plt.bar(range(len(d)), d.values(), color=colors) plt.xticks(range(len(d)), d.keys()) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt # Make a solid vertical line at x=3 and label it "cutoff". Show legend of this plot. # SOLUTION START
plt.axvline(x=3, label="cutoff") plt.legend()
import matplotlib.pyplot as plt from PIL import Image import numpy as np def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): plt.axvline(x=3, label="cutoff") plt.legend() plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() plt.show() assert len(ax.get_lines()) == 1 assert ax.get_lines()[0]._x[0] == 3 assert len(ax.legend_.get_lines()) == 1 assert ax.legend_.get_texts()[0].get_text() == "cutoff" return 1 exec_context = r""" import matplotlib.pyplot as plt [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
616
105
Matplotlib
1
Origin
105
Given this code block: ``` import matplotlib.pyplot as plt ``` Please help me to: - Make a solid vertical line at x=3 and label it "cutoff". Show legend of this plot. - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt from PIL import Image import numpy as np def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): plt.axvline(x=3, label="cutoff") plt.legend() plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() plt.show() assert len(ax.get_lines()) == 1 assert ax.get_lines()[0]._x[0] == 3 assert len(ax.legend_.get_lines()) == 1 assert ax.legend_.get_texts()[0].get_text() == "cutoff" return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt plt.axvline(x=3, label="cutoff") plt.legend() plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt labels = ["a", "b"] height = [3, 4] # Use polar projection for the figure and make a bar plot with labels in `labels` and bar height in `height` # SOLUTION START
fig, ax = plt.subplots(subplot_kw={"projection": "polar"}) plt.bar(labels, height)
import matplotlib.pyplot as plt from PIL import Image import numpy as np def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): labels = ["a", "b"] height = [3, 4] fig, ax = plt.subplots(subplot_kw={"projection": "polar"}) plt.bar(labels, height) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.name == "polar" return 1 exec_context = r""" import matplotlib.pyplot as plt labels = ["a", "b"] height = [3, 4] [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
617
106
Matplotlib
1
Origin
106
Given this code block: ``` import matplotlib.pyplot as plt labels = ["a", "b"] height = [3, 4] ``` Please help me to: - Use polar projection for the figure and make a bar plot with labels in `labels` and bar height in `height` - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt from PIL import Image import numpy as np def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): labels = ["a", "b"] height = [3, 4] fig, ax = plt.subplots(subplot_kw={"projection": "polar"}) plt.bar(labels, height) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.name == "polar" return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt labels = ["a", "b"] height = [3, 4] fig, ax = plt.subplots(subplot_kw={"projection": "polar"}) plt.bar(labels, height) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt l = ["a", "b", "c"] data = [225, 90, 50] # Make a donut plot of using `data` and use `l` for the pie labels # Set the wedge width to be 0.4 # SOLUTION START
plt.pie(data, labels=l, wedgeprops=dict(width=0.4))
import matplotlib.pyplot as plt from PIL import Image import numpy as np import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): l = ["a", "b", "c"] data = [225, 90, 50] plt.pie(data, labels=l, wedgeprops=dict(width=0.4)) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): l = ["a", "b", "c"] code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() count = 0 text_labels = [] for c in ax.get_children(): if isinstance(c, matplotlib.patches.Wedge): count += 1 assert c.width == 0.4 if isinstance(c, matplotlib.text.Text): text_labels.append(c.get_text()) for _label in l: assert _label in text_labels assert count == 3 return 1 exec_context = r""" import matplotlib.pyplot as plt l = ["a", "b", "c"] data = [225, 90, 50] [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
618
107
Matplotlib
1
Origin
107
Given this code block: ``` import matplotlib.pyplot as plt l = ["a", "b", "c"] data = [225, 90, 50] ``` Please help me to: - Make a donut plot of using `data` and use `l` for the pie labels - Set the wedge width to be 0.4 - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt from PIL import Image import numpy as np import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): l = ["a", "b", "c"] data = [225, 90, 50] plt.pie(data, labels=l, wedgeprops=dict(width=0.4)) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): l = ["a", "b", "c"] code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() count = 0 text_labels = [] for c in ax.get_children(): if isinstance(c, matplotlib.patches.Wedge): count += 1 assert c.width == 0.4 if isinstance(c, matplotlib.text.Text): text_labels.append(c.get_text()) for _label in l: assert _label in text_labels assert count == 3 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt l = ["a", "b", "c"] data = [225, 90, 50] plt.pie(data, labels=l, wedgeprops=dict(width=0.4)) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x and show blue dashed grid lines # SOLUTION START
plt.plot(y, x) plt.grid(color="blue", linestyle="dashed")
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(y, x) plt.grid(color="blue", linestyle="dashed") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.xaxis._major_tick_kw["gridOn"] assert "grid_color" in ax.xaxis._major_tick_kw assert ax.xaxis._major_tick_kw["grid_color"] in ["blue", "b"] assert "grid_linestyle" in ax.xaxis._major_tick_kw assert ax.xaxis._major_tick_kw["grid_linestyle"] in ["dashed", "--", "-.", ":"] return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
619
108
Matplotlib
1
Origin
108
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x and show blue dashed grid lines - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(y, x) plt.grid(color="blue", linestyle="dashed") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.xaxis._major_tick_kw["gridOn"] assert "grid_color" in ax.xaxis._major_tick_kw assert ax.xaxis._major_tick_kw["grid_color"] in ["blue", "b"] assert "grid_linestyle" in ax.xaxis._major_tick_kw assert ax.xaxis._major_tick_kw["grid_linestyle"] in ["dashed", "--", "-.", ":"] return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(y, x) plt.grid(color="blue", linestyle="dashed") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x # Turn minor ticks on and show gray dashed minor grid lines # Do not show any major grid lines # SOLUTION START
plt.plot(y, x) plt.minorticks_on() plt.grid(color="gray", linestyle="dashed", which="minor")
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(y, x) plt.minorticks_on() plt.grid(color="gray", linestyle="dashed", which="minor") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert not ax.xaxis._major_tick_kw["gridOn"] assert ax.xaxis._minor_tick_kw["gridOn"] assert not ax.yaxis._major_tick_kw["gridOn"] assert ax.yaxis._minor_tick_kw["gridOn"] assert ax.xaxis._minor_tick_kw["tick1On"] assert "grid_linestyle" in ax.xaxis._minor_tick_kw return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
620
109
Matplotlib
1
Origin
109
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x - Turn minor ticks on and show gray dashed minor grid lines - Do not show any major grid lines - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(y, x) plt.minorticks_on() plt.grid(color="gray", linestyle="dashed", which="minor") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert not ax.xaxis._major_tick_kw["gridOn"] assert ax.xaxis._minor_tick_kw["gridOn"] assert not ax.yaxis._major_tick_kw["gridOn"] assert ax.yaxis._minor_tick_kw["gridOn"] assert ax.xaxis._minor_tick_kw["tick1On"] assert "grid_linestyle" in ax.xaxis._minor_tick_kw return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(y, x) plt.minorticks_on() plt.grid(color="gray", linestyle="dashed", which="minor") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt labels = ["Walking", "Talking", "Sleeping", "Working"] sizes = [23, 45, 12, 20] colors = ["red", "blue", "green", "yellow"] # Make a pie chart with data in `sizes` and use `labels` as the pie labels and `colors` as the pie color. # Bold the pie labels # SOLUTION START
plt.pie(sizes, colors=colors, labels=labels, textprops={"weight": "bold"})
import matplotlib.pyplot as plt from PIL import Image import numpy as np def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): labels = ["Walking", "Talking", "Sleeping", "Working"] sizes = [23, 45, 12, 20] colors = ["red", "blue", "green", "yellow"] plt.pie(sizes, colors=colors, labels=labels, textprops={"weight": "bold"}) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.texts) == 4 for t in ax.texts: assert "bold" in t.get_fontweight() return 1 exec_context = r""" import matplotlib.pyplot as plt labels = ["Walking", "Talking", "Sleeping", "Working"] sizes = [23, 45, 12, 20] colors = ["red", "blue", "green", "yellow"] [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
621
110
Matplotlib
1
Origin
110
Given this code block: ``` import matplotlib.pyplot as plt labels = ["Walking", "Talking", "Sleeping", "Working"] sizes = [23, 45, 12, 20] colors = ["red", "blue", "green", "yellow"] ``` Please help me to: - Make a pie chart with data in `sizes` and use `labels` as the pie labels and `colors` as the pie color. - Bold the pie labels - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt from PIL import Image import numpy as np def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): labels = ["Walking", "Talking", "Sleeping", "Working"] sizes = [23, 45, 12, 20] colors = ["red", "blue", "green", "yellow"] plt.pie(sizes, colors=colors, labels=labels, textprops={"weight": "bold"}) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.texts) == 4 for t in ax.texts: assert "bold" in t.get_fontweight() return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt labels = ["Walking", "Talking", "Sleeping", "Working"] sizes = [23, 45, 12, 20] colors = ["red", "blue", "green", "yellow"] plt.pie(sizes, colors=colors, labels=labels, textprops={"weight": "bold"}) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt labels = ["Walking", "Talking", "Sleeping", "Working"] sizes = [23, 45, 12, 20] colors = ["red", "blue", "green", "yellow"] # Make a pie chart with data in `sizes` and use `labels` as the pie labels and `colors` as the pie color. # Bold the pie labels # SOLUTION START
plt.pie(sizes, colors=colors, labels=labels, textprops={"weight": "bold"})
import matplotlib.pyplot as plt from PIL import Image import numpy as np def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): labels = ["Walking", "Talking", "Sleeping", "Working"] sizes = [23, 45, 12, 20] colors = ["red", "blue", "green", "yellow"] plt.pie(sizes, colors=colors, labels=labels, textprops={"weight": "bold"}) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.texts) == 4 for t in ax.texts: assert "bold" in t.get_fontweight() return 1 exec_context = r""" import matplotlib.pyplot as plt labels = ["Walking", "Talking", "Sleeping", "Working"] sizes = [23, 45, 12, 20] colors = ["red", "blue", "green", "yellow"] [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
622
111
Matplotlib
1
Origin
111
Given this code block: ``` import matplotlib.pyplot as plt labels = ["Walking", "Talking", "Sleeping", "Working"] sizes = [23, 45, 12, 20] colors = ["red", "blue", "green", "yellow"] ``` Please help me to: - Make a pie chart with data in `sizes` and use `labels` as the pie labels and `colors` as the pie color. - Bold the pie labels - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt from PIL import Image import numpy as np def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): labels = ["Walking", "Talking", "Sleeping", "Working"] sizes = [23, 45, 12, 20] colors = ["red", "blue", "green", "yellow"] plt.pie(sizes, colors=colors, labels=labels, textprops={"weight": "bold"}) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.texts) == 4 for t in ax.texts: assert "bold" in t.get_fontweight() return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt labels = ["Walking", "Talking", "Sleeping", "Working"] sizes = [23, 45, 12, 20] colors = ["red", "blue", "green", "yellow"] plt.pie(sizes, colors=colors, labels=labels, textprops={"weight": "bold"}) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x in a line chart but use transparent marker with non-transparent edge # SOLUTION START
plt.plot( x, y, "-o", ms=14, markerfacecolor="None", markeredgecolor="red", markeredgewidth=5 )
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot( x, y, "-o", ms=14, markerfacecolor="None", markeredgecolor="red", markeredgewidth=5, ) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() line = ax.get_lines()[0] assert line.get_markerfacecolor().lower() == "none" assert line.get_markeredgecolor().lower() != "none" assert line.get_linewidth() > 0 return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
623
112
Matplotlib
1
Origin
112
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x in a line chart but use transparent marker with non-transparent edge - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot( x, y, "-o", ms=14, markerfacecolor="None", markeredgecolor="red", markeredgewidth=5, ) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() line = ax.get_lines()[0] assert line.get_markerfacecolor().lower() == "none" assert line.get_markeredgecolor().lower() != "none" assert line.get_linewidth() > 0 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot( x, y, "-o", ms=14, markerfacecolor="None", markeredgecolor="red", markeredgewidth=5 ) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[ ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"] ] sns.distplot(df["bill_length_mm"], color="blue") # Plot a vertical line at 55 with green color # SOLUTION START
plt.axvline(55, color="green")
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("penguins")[ ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"] ] sns.distplot(df["bill_length_mm"], color="blue") plt.axvline(55, color="green") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.lines) == 2 assert isinstance(ax.lines[1], matplotlib.lines.Line2D) assert tuple(ax.lines[1].get_xdata()) == (55, 55) return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[ ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"] ] sns.distplot(df["bill_length_mm"], color="blue") [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
624
113
Matplotlib
1
Origin
113
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[ ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"] ] sns.distplot(df["bill_length_mm"], color="blue") ``` Please help me to: - Plot a vertical line at 55 with green color - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("penguins")[ ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"] ] sns.distplot(df["bill_length_mm"], color="blue") plt.axvline(55, color="green") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.lines) == 2 assert isinstance(ax.lines[1], matplotlib.lines.Line2D) assert tuple(ax.lines[1].get_xdata()) == (55, 55) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[ ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"] ] sns.distplot(df["bill_length_mm"], color="blue") plt.axvline(55, color="green") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt import numpy as np # Specify the values of blue bars (height) blue_bar = (23, 25, 17) # Specify the values of orange bars (height) orange_bar = (19, 18, 14) # Plot the blue bar and the orange bar side-by-side in the same bar plot. # Make sure the bars don't overlap with each other. # SOLUTION START
# Position of bars on x-axis ind = np.arange(len(blue_bar)) # Figure size plt.figure(figsize=(10, 5)) # Width of a bar width = 0.3 plt.bar(ind, blue_bar, width, label="Blue bar label") plt.bar(ind + width, orange_bar, width, label="Orange bar label")
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): blue_bar = (23, 25, 17) orange_bar = (19, 18, 14) ind = np.arange(len(blue_bar)) plt.figure(figsize=(10, 5)) width = 0.3 plt.bar(ind, blue_bar, width, label="Blue bar label") plt.bar(ind + width, orange_bar, width, label="Orange bar label") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.patches) == 6 x_positions = [rec.get_x() for rec in ax.patches] assert len(x_positions) == len(set(x_positions)) return 1 exec_context = r""" import matplotlib.pyplot as plt import numpy as np blue_bar = (23, 25, 17) orange_bar = (19, 18, 14) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
625
114
Matplotlib
1
Origin
114
Given this code block: ``` import matplotlib.pyplot as plt import numpy as np blue_bar = (23, 25, 17) orange_bar = (19, 18, 14) ``` Please help me to: - Specify the values of blue bars (height) - Specify the values of orange bars (height) - Plot the blue bar and the orange bar side-by-side in the same bar plot. - Make sure the bars don't overlap with each other. - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): blue_bar = (23, 25, 17) orange_bar = (19, 18, 14) ind = np.arange(len(blue_bar)) plt.figure(figsize=(10, 5)) width = 0.3 plt.bar(ind, blue_bar, width, label="Blue bar label") plt.bar(ind + width, orange_bar, width, label="Orange bar label") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.patches) == 6 x_positions = [rec.get_x() for rec in ax.patches] assert len(x_positions) == len(set(x_positions)) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt import numpy as np blue_bar = (23, 25, 17) orange_bar = (19, 18, 14) # Position of bars on x-axis ind = np.arange(len(blue_bar)) # Figure size plt.figure(figsize=(10, 5)) # Width of a bar width = 0.3 plt.bar(ind, blue_bar, width, label="Blue bar label") plt.bar(ind + width, orange_bar, width, label="Orange bar label") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.random.rand(10) z = np.random.rand(10) a = np.arange(10) # Make two subplots # Plot y over x in the first subplot and plot z over a in the second subplot # Label each line chart and put them into a single legend on the first subplot # SOLUTION START
fig, ax = plt.subplots(2, 1) (l1,) = ax[0].plot(x, y, color="red", label="y") (l2,) = ax[1].plot(a, z, color="blue", label="z") ax[0].legend([l1, l2], ["z", "y"])
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.random.rand(10) z = np.random.rand(10) a = np.arange(10) fig, ax = plt.subplots(2, 1) (l1,) = ax[0].plot(x, y, color="red", label="y") (l2,) = ax[1].plot(a, z, color="blue", label="z") ax[0].legend([l1, l2], ["z", "y"]) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() axes = np.array(f.get_axes()) axes = axes.reshape(-1) assert len(axes) == 2 l = axes[0].get_legend() assert l is not None assert len(l.get_texts()) == 2 assert len(axes[0].get_lines()) == 1 assert len(axes[1].get_lines()) == 1 return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.random.rand(10) z = np.random.rand(10) a = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
626
115
Matplotlib
1
Origin
115
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.random.rand(10) z = np.random.rand(10) a = np.arange(10) ``` Please help me to: - Make two subplots - Plot y over x in the first subplot and plot z over a in the second subplot - Label each line chart and put them into a single legend on the first subplot - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.random.rand(10) z = np.random.rand(10) a = np.arange(10) fig, ax = plt.subplots(2, 1) (l1,) = ax[0].plot(x, y, color="red", label="y") (l2,) = ax[1].plot(a, z, color="blue", label="z") ax[0].legend([l1, l2], ["z", "y"]) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() axes = np.array(f.get_axes()) axes = axes.reshape(-1) assert len(axes) == 2 l = axes[0].get_legend() assert l is not None assert len(l.get_texts()) == 2 assert len(axes[0].get_lines()) == 1 assert len(axes[1].get_lines()) == 1 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.random.rand(10) z = np.random.rand(10) a = np.arange(10) fig, ax = plt.subplots(2, 1) (l1,) = ax[0].plot(x, y, color="red", label="y") (l2,) = ax[1].plot(a, z, color="blue", label="z") ax[0].legend([l1, l2], ["z", "y"]) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib x = np.arange(10) y = np.linspace(0, 1, 10) # Plot y over x with a scatter plot # Use the "Spectral" colormap and color each data point based on the y-value # SOLUTION START
plt.scatter(x, y, c=y, cmap="Spectral")
import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.linspace(0, 1, 10) plt.scatter(x, y, c=y, cmap="Spectral") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.collections) == 1 assert ax.collections[0].get_cmap().name == "Spectral" return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib x = np.arange(10) y = np.linspace(0, 1, 10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
627
116
Matplotlib
1
Origin
116
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib x = np.arange(10) y = np.linspace(0, 1, 10) ``` Please help me to: - Plot y over x with a scatter plot - Use the "Spectral" colormap and color each data point based on the y-value - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.linspace(0, 1, 10) plt.scatter(x, y, c=y, cmap="Spectral") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.collections) == 1 assert ax.collections[0].get_cmap().name == "Spectral" return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib x = np.arange(10) y = np.linspace(0, 1, 10) plt.scatter(x, y, c=y, cmap="Spectral") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # plot y over x # use a tick interval of 1 on the a-axis # SOLUTION START
plt.plot(x, y) plt.xticks(np.arange(min(x), max(x) + 1, 1.0))
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.xticks(np.arange(min(x), max(x) + 1, 1.0)) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() xticks = ax.get_xticks() assert ( ax.get_xticks() == np.arange(ax.get_xticks().min(), ax.get_xticks().max() + 1, 1) ).all() return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
628
117
Matplotlib
1
Origin
117
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - plot y over x - use a tick interval of 1 on the a-axis - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.xticks(np.arange(min(x), max(x) + 1, 1.0)) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() xticks = ax.get_xticks() assert ( ax.get_xticks() == np.arange(ax.get_xticks().min(), ax.get_xticks().max() + 1, 1) ).all() return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.xticks(np.arange(min(x), max(x) + 1, 1.0)) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[["bill_length_mm", "species", "sex"]] # Use seaborn catplot to plot multiple barplots of "bill_length_mm" over "sex" and separate into different subplot columns by "species" # Do not share y axis across subplots # SOLUTION START
sns.catplot( x="sex", col="species", y="bill_length_mm", data=df, kind="bar", sharey=False )
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("penguins")[["bill_length_mm", "species", "sex"]] sns.catplot( x="sex", col="species", y="bill_length_mm", data=df, kind="bar", sharey=False ) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert len(f.axes) == 3 for ax in f.axes: assert ax.get_xlabel() == "sex" assert len(ax.patches) == 2 assert f.axes[0].get_ylabel() == "bill_length_mm" assert len(f.axes[0].get_yticks()) != len( f.axes[1].get_yticks() ) or not np.allclose(f.axes[0].get_yticks(), f.axes[1].get_yticks()) return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[["bill_length_mm", "species", "sex"]] [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
629
118
Matplotlib
1
Origin
118
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[["bill_length_mm", "species", "sex"]] ``` Please help me to: - Use seaborn catplot to plot multiple barplots of "bill_length_mm" over "sex" and separate into different subplot columns by "species" - Do not share y axis across subplots - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("penguins")[["bill_length_mm", "species", "sex"]] sns.catplot( x="sex", col="species", y="bill_length_mm", data=df, kind="bar", sharey=False ) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert len(f.axes) == 3 for ax in f.axes: assert ax.get_xlabel() == "sex" assert len(ax.patches) == 2 assert f.axes[0].get_ylabel() == "bill_length_mm" assert len(f.axes[0].get_yticks()) != len( f.axes[1].get_yticks() ) or not np.allclose(f.axes[0].get_yticks(), f.axes[1].get_yticks()) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[["bill_length_mm", "species", "sex"]] sns.catplot( x="sex", col="species", y="bill_length_mm", data=df, kind="bar", sharey=False ) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt # draw a circle centered at (0.5, 0.5) with radius 0.2 # SOLUTION START
import matplotlib.pyplot as plt circle1 = plt.Circle((0.5, 0.5), 0.2) plt.gca().add_patch(circle1)
import matplotlib.pyplot as plt from PIL import Image import numpy as np import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): circle1 = plt.Circle((0.5, 0.5), 0.2) plt.gca().add_patch(circle1) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.patches) == 1 assert isinstance(ax.patches[0], matplotlib.patches.Circle) assert ax.patches[0].get_radius() == 0.2 assert ax.patches[0].get_center() == (0.5, 0.5) return 1 exec_context = r""" import matplotlib.pyplot as plt [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
630
119
Matplotlib
1
Origin
119
Given this code block: ``` import matplotlib.pyplot as plt ``` Please help me to: - draw a circle centered at (0.5, 0.5) with radius 0.2 - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt from PIL import Image import numpy as np import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): circle1 = plt.Circle((0.5, 0.5), 0.2) plt.gca().add_patch(circle1) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.patches) == 1 assert isinstance(ax.patches[0], matplotlib.patches.Circle) assert ax.patches[0].get_radius() == 0.2 assert ax.patches[0].get_center() == (0.5, 0.5) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt import matplotlib.pyplot as plt circle1 = plt.Circle((0.5, 0.5), 0.2) plt.gca().add_patch(circle1) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x and use the greek letter phi for title. Bold the title and make sure phi is bold. # SOLUTION START
plt.plot(y, x) plt.title(r"$\mathbf{\phi}$")
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(y, x) plt.title(r"$\mathbf{\phi}$") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert "\\phi" in ax.get_title() assert "bf" in ax.get_title() assert "$" in ax.get_title() return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
631
120
Matplotlib
1
Origin
120
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x and use the greek letter phi for title. Bold the title and make sure phi is bold. - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(y, x) plt.title(r"$\mathbf{\phi}$") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert "\\phi" in ax.get_title() assert "bf" in ax.get_title() assert "$" in ax.get_title() return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(y, x) plt.title(r"$\mathbf{\phi}$") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x with a legend of "Line" # Adjust the spacing between legend markers and labels to be 0.1 # SOLUTION START
plt.plot(x, y, label="Line") plt.legend(handletextpad=0.1)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y, label="Line") plt.legend(handletextpad=0.1) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.get_legend().get_texts()) > 0 assert ax.get_legend().handletextpad == 0.1 return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
632
121
Matplotlib
1
Origin
121
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x with a legend of "Line" - Adjust the spacing between legend markers and labels to be 0.1 - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y, label="Line") plt.legend(handletextpad=0.1) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.get_legend().get_texts()) > 0 assert ax.get_legend().handletextpad == 0.1 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y, label="Line") plt.legend(handletextpad=0.1) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x with a legend of "Line" # Adjust the length of the legend handle to be 0.3 # SOLUTION START
plt.plot(x, y, label="Line") plt.legend(handlelength=0.3)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y, label="Line") plt.legend(handlelength=0.3) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.get_legend().get_texts()) > 0 assert ax.get_legend().handlelength == 0.3 return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
633
122
Matplotlib
1
Semantic
121
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x with a legend of "Line" - Adjust the length of the legend handle to be 0.3 - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y, label="Line") plt.legend(handlelength=0.3) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.get_legend().get_texts()) > 0 assert ax.get_legend().handlelength == 0.3 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y, label="Line") plt.legend(handlelength=0.3) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y, label="Line") plt.plot(y, x, label="Flipped") # Show a two columns legend of this plot # SOLUTION START
plt.legend(ncol=2)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y, label="Line") plt.plot(y, x, label="Flipped") plt.legend(ncol=2) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.get_legend()._ncols == 2 return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y, label="Line") plt.plot(y, x, label="Flipped") [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
634
123
Matplotlib
1
Semantic
121
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y, label="Line") plt.plot(y, x, label="Flipped") ``` Please help me to: - Show a two columns legend of this plot - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y, label="Line") plt.plot(y, x, label="Flipped") plt.legend(ncol=2) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.get_legend()._ncols == 2 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y, label="Line") plt.plot(y, x, label="Flipped") plt.legend(ncol=2) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y, marker="*", label="Line") # Show a legend of this plot and show two markers on the line # SOLUTION START
plt.legend(numpoints=2)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y, marker="*", label="Line") plt.legend(numpoints=2) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.get_legend().numpoints == 2 return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y, marker="*", label="Line") [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
635
124
Matplotlib
1
Semantic
121
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y, marker="*", label="Line") ``` Please help me to: - Show a legend of this plot and show two markers on the line - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y, marker="*", label="Line") plt.legend(numpoints=2) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.get_legend().numpoints == 2 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y, marker="*", label="Line") plt.legend(numpoints=2) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt import numpy as np data = np.random.random((10, 10)) # plot the 2d matrix data with a colorbar # SOLUTION START
plt.imshow(data) plt.colorbar()
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): data = np.random.random((10, 10)) plt.imshow(data) plt.colorbar() plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert len(f.axes) == 2 assert len(f.axes[0].images) == 1 assert f.axes[1].get_label() == "<colorbar>" return 1 exec_context = r""" import matplotlib.pyplot as plt import numpy as np data = np.random.random((10, 10)) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
636
125
Matplotlib
1
Origin
125
Given this code block: ``` import matplotlib.pyplot as plt import numpy as np data = np.random.random((10, 10)) ``` Please help me to: - plot the 2d matrix data with a colorbar - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): data = np.random.random((10, 10)) plt.imshow(data) plt.colorbar() plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert len(f.axes) == 2 assert len(f.axes[0].images) == 1 assert f.axes[1].get_label() == "<colorbar>" return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt import numpy as np data = np.random.random((10, 10)) plt.imshow(data) plt.colorbar() plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x. Give the plot a title "Figure 1". bold the word "Figure" in the title but do not bold "1" # SOLUTION START
plt.plot(x, y) plt.title(r"$\bf{Figure}$ 1")
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.title(r"$\bf{Figure}$ 1") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert "bf" in ax.get_title() assert "$" in ax.get_title() return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
637
126
Matplotlib
1
Origin
126
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x. Give the plot a title "Figure 1". bold the word "Figure" in the title but do not bold "1" - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.title(r"$\bf{Figure}$ 1") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert "bf" in ax.get_title() assert "$" in ax.get_title() return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.title(r"$\bf{Figure}$ 1") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt import seaborn as sns import pandas as pd df = pd.DataFrame( { "id": ["1", "2", "1", "2", "2"], "x": [123, 22, 356, 412, 54], "y": [120, 12, 35, 41, 45], } ) # Use seaborn to make a pairplot of data in `df` using `x` for x_vars, `y` for y_vars, and `id` for hue # Hide the legend in the output figure # SOLUTION START
g = sns.pairplot(df, x_vars=["x"], y_vars=["y"], hue="id") g._legend.remove()
import matplotlib.pyplot as plt import seaborn as sns import pandas as pd from PIL import Image import numpy as np def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = pd.DataFrame( { "id": ["1", "2", "1", "2", "2"], "x": [123, 22, 356, 412, 54], "y": [120, 12, 35, 41, 45], } ) g = sns.pairplot(df, x_vars=["x"], y_vars=["y"], hue="id") g._legend.remove() plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert len(f.axes) == 1 if len(f.legends) == 0: for ax in f.axes: if ax.get_legend() is not None: assert not ax.get_legend()._visible else: for l in f.legends: assert not l._visible return 1 exec_context = r""" import matplotlib.pyplot as plt import seaborn as sns import pandas as pd df = pd.DataFrame( { "id": ["1", "2", "1", "2", "2"], "x": [123, 22, 356, 412, 54], "y": [120, 12, 35, 41, 45], } ) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
638
127
Matplotlib
1
Origin
127
Given this code block: ``` import matplotlib.pyplot as plt import seaborn as sns import pandas as pd df = pd.DataFrame( { "id": ["1", "2", "1", "2", "2"], "x": [123, 22, 356, 412, 54], "y": [120, 12, 35, 41, 45], } ) ``` Please help me to: - Use seaborn to make a pairplot of data in `df` using `x` for x_vars, `y` for y_vars, and `id` for hue - Hide the legend in the output figure - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt import seaborn as sns import pandas as pd from PIL import Image import numpy as np def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = pd.DataFrame( { "id": ["1", "2", "1", "2", "2"], "x": [123, 22, 356, 412, 54], "y": [120, 12, 35, 41, 45], } ) g = sns.pairplot(df, x_vars=["x"], y_vars=["y"], hue="id") g._legend.remove() plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert len(f.axes) == 1 if len(f.legends) == 0: for ax in f.axes: if ax.get_legend() is not None: assert not ax.get_legend()._visible else: for l in f.legends: assert not l._visible return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt import seaborn as sns import pandas as pd df = pd.DataFrame( { "id": ["1", "2", "1", "2", "2"], "x": [123, 22, 356, 412, 54], "y": [120, 12, 35, 41, 45], } ) g = sns.pairplot(df, x_vars=["x"], y_vars=["y"], hue="id") g._legend.remove() plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x and invert the x axis # SOLUTION START
plt.plot(x, y) plt.gca().invert_xaxis()
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.gca().invert_xaxis() plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.get_xlim()[0] > ax.get_xlim()[1] return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
639
128
Matplotlib
1
Origin
128
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x and invert the x axis - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.gca().invert_xaxis() plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.get_xlim()[0] > ax.get_xlim()[1] return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.gca().invert_xaxis() plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(11) y = np.arange(11) plt.xlim(0, 10) plt.ylim(0, 10) # Plot a scatter plot x over y and set both the x limit and y limit to be between 0 and 10 # Turn off axis clipping so data points can go beyond the axes # SOLUTION START
plt.scatter(x, y, clip_on=False)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(11) y = np.arange(11) plt.xlim(0, 10) plt.ylim(0, 10) plt.scatter(x, y, clip_on=False) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert not ax.collections[0].get_clip_on() assert ax.get_xlim() == (0.0, 10.0) assert ax.get_ylim() == (0.0, 10.0) return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(11) y = np.arange(11) plt.xlim(0, 10) plt.ylim(0, 10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
640
129
Matplotlib
1
Origin
129
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(11) y = np.arange(11) plt.xlim(0, 10) plt.ylim(0, 10) ``` Please help me to: - Plot a scatter plot x over y and set both the x limit and y limit to be between 0 and 10 - Turn off axis clipping so data points can go beyond the axes - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(11) y = np.arange(11) plt.xlim(0, 10) plt.ylim(0, 10) plt.scatter(x, y, clip_on=False) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert not ax.collections[0].get_clip_on() assert ax.get_xlim() == (0.0, 10.0) assert ax.get_ylim() == (0.0, 10.0) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(11) y = np.arange(11) plt.xlim(0, 10) plt.ylim(0, 10) plt.scatter(x, y, clip_on=False) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot a scatter plot with values in x and y # Plot the data points to have red inside and have black border # SOLUTION START
plt.scatter(x, y, c="red", edgecolors="black")
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.scatter(x, y, c="red", edgecolors="black") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.collections) > 0 assert len(ax.collections[0]._edgecolors) == 1 assert len(ax.collections[0]._facecolors) == 1 assert tuple(ax.collections[0]._edgecolors[0]) == (0.0, 0.0, 0.0, 1.0) assert tuple(ax.collections[0]._facecolors[0]) == (1.0, 0.0, 0.0, 1.0) return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
641
130
Matplotlib
1
Origin
130
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot a scatter plot with values in x and y - Plot the data points to have red inside and have black border - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.scatter(x, y, c="red", edgecolors="black") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.collections) > 0 assert len(ax.collections[0]._edgecolors) == 1 assert len(ax.collections[0]._facecolors) == 1 assert tuple(ax.collections[0]._edgecolors[0]) == (0.0, 0.0, 0.0, 1.0) assert tuple(ax.collections[0]._facecolors[0]) == (1.0, 0.0, 0.0, 1.0) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.scatter(x, y, c="red", edgecolors="black") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # plot y over x on a 2 by 2 subplots with a figure size of (15, 15) # repeat the plot in each subplot # SOLUTION START
f, axs = plt.subplots(2, 2, figsize=(15, 15)) for ax in f.axes: ax.plot(x, y)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) f, axs = plt.subplots(2, 2, figsize=(15, 15)) for ax in f.axes: ax.plot(x, y) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert (f.get_size_inches() == (15, 15)).all() for ax in f.axes: assert len(ax.get_lines()) == 1 return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
642
131
Matplotlib
1
Origin
131
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - plot y over x on a 2 by 2 subplots with a figure size of (15, 15) - repeat the plot in each subplot - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) f, axs = plt.subplots(2, 2, figsize=(15, 15)) for ax in f.axes: ax.plot(x, y) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert (f.get_size_inches() == (15, 15)).all() for ax in f.axes: assert len(ax.get_lines()) == 1 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) f, axs = plt.subplots(2, 2, figsize=(15, 15)) for ax in f.axes: ax.plot(x, y) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.random.rand(100) * 10 # Make a histogram of x # Make the histogram range from 0 to 10 # Make bar width 2 for each bar in the histogram and have 5 bars in total # SOLUTION START
plt.hist(x, bins=np.arange(0, 11, 2))
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.random.rand(100) * 10 plt.hist(x, bins=np.arange(0, 11, 2)) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.patches) == 5 for i in range(5): assert ax.patches[i].get_width() == 2.0 return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.random.rand(100) * 10 [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
643
132
Matplotlib
1
Origin
132
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.random.rand(100) * 10 ``` Please help me to: - Make a histogram of x - Make the histogram range from 0 to 10 - Make bar width 2 for each bar in the histogram and have 5 bars in total - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.random.rand(100) * 10 plt.hist(x, bins=np.arange(0, 11, 2)) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.patches) == 5 for i in range(5): assert ax.patches[i].get_width() == 2.0 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.random.rand(100) * 10 plt.hist(x, bins=np.arange(0, 11, 2)) plt.savefig('output.png', bbox_inches ='tight') result = None return result
from matplotlib import pyplot as plt import numpy as np x = np.arange(10) y = np.arange(1, 11) error = np.random.random(y.shape) # Plot y over x and show the error according to `error` # Plot the error as a shaded region rather than error bars # SOLUTION START
plt.plot(x, y, "k-") plt.fill_between(x, y - error, y + error)
from matplotlib import pyplot as plt import numpy as np from PIL import Image import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(1, 11) error = np.random.random(y.shape) plt.plot(x, y, "k-") plt.fill_between(x, y - error, y + error) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.lines) == 1 assert len(ax.collections) == 1 assert isinstance(ax.collections[0], matplotlib.collections.PolyCollection) return 1 exec_context = r""" from matplotlib import pyplot as plt import numpy as np x = np.arange(10) y = np.arange(1, 11) error = np.random.random(y.shape) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
644
133
Matplotlib
1
Origin
133
Given this code block: ``` from matplotlib import pyplot as plt import numpy as np x = np.arange(10) y = np.arange(1, 11) error = np.random.random(y.shape) ``` Please help me to: - Plot y over x and show the error according to `error` - Plot the error as a shaded region rather than error bars - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
from matplotlib import pyplot as plt import numpy as np from PIL import Image import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(1, 11) error = np.random.random(y.shape) plt.plot(x, y, "k-") plt.fill_between(x, y - error, y + error) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.lines) == 1 assert len(ax.collections) == 1 assert isinstance(ax.collections[0], matplotlib.collections.PolyCollection) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): from matplotlib import pyplot as plt import numpy as np x = np.arange(10) y = np.arange(1, 11) error = np.random.random(y.shape) plt.plot(x, y, "k-") plt.fill_between(x, y - error, y + error) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt import numpy as np xvec = np.linspace(-5.0, 5.0, 100) x, y = np.meshgrid(xvec, xvec) z = -np.hypot(x, y) plt.contourf(x, y, z) # draw x=0 and y=0 axis in my contour plot with white color # SOLUTION START
plt.axhline(0, color="white") plt.axvline(0, color="white")
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): xvec = np.linspace(-5.0, 5.0, 100) x, y = np.meshgrid(xvec, xvec) z = -np.hypot(x, y) plt.contourf(x, y, z) plt.axhline(0, color="white") plt.axvline(0, color="white") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.lines) == 2 for l in ax.lines: assert l._color == "white" or tuple(l._color) == (1, 1, 1, 1) horizontal = False vertical = False for l in ax.lines: if tuple(l.get_ydata()) == (0, 0): horizontal = True for l in ax.lines: if tuple(l.get_xdata()) == (0, 0): vertical = True assert horizontal and vertical return 1 exec_context = r""" import matplotlib.pyplot as plt import numpy as np xvec = np.linspace(-5.0, 5.0, 100) x, y = np.meshgrid(xvec, xvec) z = -np.hypot(x, y) plt.contourf(x, y, z) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
645
134
Matplotlib
1
Origin
134
Given this code block: ``` import matplotlib.pyplot as plt import numpy as np xvec = np.linspace(-5.0, 5.0, 100) x, y = np.meshgrid(xvec, xvec) z = -np.hypot(x, y) plt.contourf(x, y, z) ``` Please help me to: - draw x=0 and y=0 axis in my contour plot with white color - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): xvec = np.linspace(-5.0, 5.0, 100) x, y = np.meshgrid(xvec, xvec) z = -np.hypot(x, y) plt.contourf(x, y, z) plt.axhline(0, color="white") plt.axvline(0, color="white") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.lines) == 2 for l in ax.lines: assert l._color == "white" or tuple(l._color) == (1, 1, 1, 1) horizontal = False vertical = False for l in ax.lines: if tuple(l.get_ydata()) == (0, 0): horizontal = True for l in ax.lines: if tuple(l.get_xdata()) == (0, 0): vertical = True assert horizontal and vertical return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt import numpy as np xvec = np.linspace(-5.0, 5.0, 100) x, y = np.meshgrid(xvec, xvec) z = -np.hypot(x, y) plt.contourf(x, y, z) plt.axhline(0, color="white") plt.axvline(0, color="white") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt import numpy as np box_position, box_height, box_errors = np.arange(4), np.ones(4), np.arange(1, 5) c = ["r", "r", "b", "b"] fig, ax = plt.subplots() ax.bar(box_position, box_height, color="yellow") # Plot error bars with errors specified in box_errors. Use colors in c to color the error bars # SOLUTION START
for pos, y, err, color in zip(box_position, box_height, box_errors, c): ax.errorbar(pos, y, err, color=color)
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): box_position, box_height, box_errors = np.arange(4), np.ones(4), np.arange(1, 5) c = ["r", "r", "b", "b"] fig, ax = plt.subplots() ax.bar(box_position, box_height, color="yellow") for pos, y, err, color in zip(box_position, box_height, box_errors, c): ax.errorbar(pos, y, err, color=color) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.get_lines()) == 4 line_colors = [] for line in ax.get_lines(): line_colors.append(line._color) assert set(line_colors) == set(c) return 1 exec_context = r""" import matplotlib.pyplot as plt import numpy as np box_position, box_height, box_errors = np.arange(4), np.ones(4), np.arange(1, 5) c = ["r", "r", "b", "b"] fig, ax = plt.subplots() ax.bar(box_position, box_height, color="yellow") [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
646
135
Matplotlib
1
Origin
135
Given this code block: ``` import matplotlib.pyplot as plt import numpy as np box_position, box_height, box_errors = np.arange(4), np.ones(4), np.arange(1, 5) c = ["r", "r", "b", "b"] fig, ax = plt.subplots() ax.bar(box_position, box_height, color="yellow") ``` Please help me to: - Plot error bars with errors specified in box_errors. Use colors in c to color the error bars - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): box_position, box_height, box_errors = np.arange(4), np.ones(4), np.arange(1, 5) c = ["r", "r", "b", "b"] fig, ax = plt.subplots() ax.bar(box_position, box_height, color="yellow") for pos, y, err, color in zip(box_position, box_height, box_errors, c): ax.errorbar(pos, y, err, color=color) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.get_lines()) == 4 line_colors = [] for line in ax.get_lines(): line_colors.append(line._color) assert set(line_colors) == set(c) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt import numpy as np box_position, box_height, box_errors = np.arange(4), np.ones(4), np.arange(1, 5) c = ["r", "r", "b", "b"] fig, ax = plt.subplots() ax.bar(box_position, box_height, color="yellow") for pos, y, err, color in zip(box_position, box_height, box_errors, c): ax.errorbar(pos, y, err, color=color) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) z = np.arange(10) a = np.arange(10) # Plot y over x and z over a in two side-by-side subplots # Make "Y" the title of the first subplot and "Z" the title of the second subplot # Raise the title of the second subplot to be higher than the first one # SOLUTION START
fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True) ax1.plot(x, y) ax1.set_title("Y") ax2.plot(a, z) ax2.set_title("Z", y=1.08)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) z = np.arange(10) a = np.arange(10) fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True) ax1.plot(x, y) ax1.set_title("Y") ax2.plot(a, z) ax2.set_title("Z", y=1.08) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert f.axes[0].get_gridspec().nrows == 1 assert f.axes[0].get_gridspec().ncols == 2 assert f.axes[1].title._y > f.axes[0].title._y return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) z = np.arange(10) a = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
647
136
Matplotlib
1
Origin
136
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) z = np.arange(10) a = np.arange(10) ``` Please help me to: - Plot y over x and z over a in two side-by-side subplots - Make "Y" the title of the first subplot and "Z" the title of the second subplot - Raise the title of the second subplot to be higher than the first one - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) z = np.arange(10) a = np.arange(10) fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True) ax1.plot(x, y) ax1.set_title("Y") ax2.plot(a, z) ax2.set_title("Z", y=1.08) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert f.axes[0].get_gridspec().nrows == 1 assert f.axes[0].get_gridspec().ncols == 2 assert f.axes[1].title._y > f.axes[0].title._y return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) z = np.arange(10) a = np.arange(10) fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True) ax1.plot(x, y) ax1.set_title("Y") ax2.plot(a, z) ax2.set_title("Z", y=1.08) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # make 4 by 4 subplots with a figure size (5,5) # in each subplot, plot y over x and show axis tick labels # give enough spacing between subplots so the tick labels don't overlap # SOLUTION START
fig, axes = plt.subplots(nrows=4, ncols=4, figsize=(5, 5)) for ax in axes.flatten(): ax.plot(x, y) fig.tight_layout()
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) fig, axes = plt.subplots(nrows=4, ncols=4, figsize=(5, 5)) for ax in axes.flatten(): ax.plot(x, y) fig.tight_layout() plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert f.subplotpars.hspace > 0.2 assert f.subplotpars.wspace > 0.2 assert len(f.axes) == 16 for ax in f.axes: assert ax.xaxis._major_tick_kw["tick1On"] assert ax.xaxis._major_tick_kw["label1On"] assert ax.yaxis._major_tick_kw["tick1On"] assert ax.yaxis._major_tick_kw["label1On"] assert len(ax.get_xticks()) > 0 assert len(ax.get_yticks()) > 0 for l in ax.get_xticklabels(): assert l.get_text() != "" for l in ax.get_yticklabels(): assert l.get_text() != "" return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
648
137
Matplotlib
1
Origin
137
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - make 4 by 4 subplots with a figure size (5,5) - in each subplot, plot y over x and show axis tick labels - give enough spacing between subplots so the tick labels don't overlap - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) fig, axes = plt.subplots(nrows=4, ncols=4, figsize=(5, 5)) for ax in axes.flatten(): ax.plot(x, y) fig.tight_layout() plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert f.subplotpars.hspace > 0.2 assert f.subplotpars.wspace > 0.2 assert len(f.axes) == 16 for ax in f.axes: assert ax.xaxis._major_tick_kw["tick1On"] assert ax.xaxis._major_tick_kw["label1On"] assert ax.yaxis._major_tick_kw["tick1On"] assert ax.yaxis._major_tick_kw["label1On"] assert len(ax.get_xticks()) > 0 assert len(ax.get_yticks()) > 0 for l in ax.get_xticklabels(): assert l.get_text() != "" for l in ax.get_yticklabels(): assert l.get_text() != "" return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) fig, axes = plt.subplots(nrows=4, ncols=4, figsize=(5, 5)) for ax in axes.flatten(): ax.plot(x, y) fig.tight_layout() plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt import numpy as np d = np.random.random((10, 10)) # Use matshow to plot d and make the figure size (8, 8) # SOLUTION START
matfig = plt.figure(figsize=(8, 8)) plt.matshow(d, fignum=matfig.number)
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): d = np.random.random((10, 10)) matfig = plt.figure(figsize=(8, 8)) plt.matshow(d, fignum=matfig.number) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert tuple(f.get_size_inches()) == (8.0, 8.0) return 1 exec_context = r""" import matplotlib.pyplot as plt import numpy as np d = np.random.random((10, 10)) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
649
138
Matplotlib
1
Origin
138
Given this code block: ``` import matplotlib.pyplot as plt import numpy as np d = np.random.random((10, 10)) ``` Please help me to: - Use matshow to plot d and make the figure size (8, 8) - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): d = np.random.random((10, 10)) matfig = plt.figure(figsize=(8, 8)) plt.matshow(d, fignum=matfig.number) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert tuple(f.get_size_inches()) == (8.0, 8.0) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt import numpy as np d = np.random.random((10, 10)) matfig = plt.figure(figsize=(8, 8)) plt.matshow(d, fignum=matfig.number) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[ ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"] ].head(10) # Plot df as a matplotlib table. Set the bbox of the table to [0, 0, 1, 1] # SOLUTION START
bbox = [0, 0, 1, 1] plt.table(cellText=df.values, rowLabels=df.index, bbox=bbox, colLabels=df.columns)
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("penguins")[ ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"] ].head(10) bbox = [0, 0, 1, 1] plt.table(cellText=df.values, rowLabels=df.index, bbox=bbox, colLabels=df.columns) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() table_in_children = False for tab in ax.get_children(): if isinstance(tab, matplotlib.table.Table): table_in_children = True break assert tuple(ax.get_children()[0]._bbox) == (0, 0, 1, 1) return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[ ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"] ].head(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
650
139
Matplotlib
1
Origin
139
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[ ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"] ].head(10) ``` Please help me to: - Plot df as a matplotlib table. Set the bbox of the table to [0, 0, 1, 1] - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("penguins")[ ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"] ].head(10) bbox = [0, 0, 1, 1] plt.table(cellText=df.values, rowLabels=df.index, bbox=bbox, colLabels=df.columns) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() table_in_children = False for tab in ax.get_children(): if isinstance(tab, matplotlib.table.Table): table_in_children = True break assert tuple(ax.get_children()[0]._bbox) == (0, 0, 1, 1) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[ ["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"] ].head(10) bbox = [0, 0, 1, 1] plt.table(cellText=df.values, rowLabels=df.index, bbox=bbox, colLabels=df.columns) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x in a line chart. Show x axis tick labels on both top and bottom of the figure. # SOLUTION START
plt.plot(x, y) plt.tick_params(labeltop=True)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.tick_params(labeltop=True) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.xaxis._major_tick_kw["label2On"] assert ax.xaxis._major_tick_kw["label1On"] return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
651
140
Matplotlib
1
Origin
140
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x in a line chart. Show x axis tick labels on both top and bottom of the figure. - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.tick_params(labeltop=True) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.xaxis._major_tick_kw["label2On"] assert ax.xaxis._major_tick_kw["label1On"] return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.tick_params(labeltop=True) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x in a line chart. Show x axis ticks on both top and bottom of the figure. # SOLUTION START
plt.plot(x, y) plt.tick_params(top=True)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.tick_params(top=True) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.xaxis._major_tick_kw["tick2On"] assert ax.xaxis._major_tick_kw["tick1On"] return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
652
141
Matplotlib
1
Semantic
140
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x in a line chart. Show x axis ticks on both top and bottom of the figure. - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.tick_params(top=True) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.xaxis._major_tick_kw["tick2On"] assert ax.xaxis._major_tick_kw["tick1On"] return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.tick_params(top=True) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x in a line chart. Show x axis tick labels but hide the x axis ticks # SOLUTION START
plt.plot(x, y) plt.tick_params(bottom=False, labelbottom=True)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.tick_params(bottom=False, labelbottom=True) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() plt.show() assert not ax.xaxis._major_tick_kw["tick1On"] assert ax.xaxis._major_tick_kw["label1On"] assert len(ax.get_xticks()) > 0 for l in ax.get_xticklabels(): assert l.get_text() != "" return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
653
142
Matplotlib
1
Semantic
140
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x in a line chart. Show x axis tick labels but hide the x axis ticks - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.tick_params(bottom=False, labelbottom=True) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() plt.show() assert not ax.xaxis._major_tick_kw["tick1On"] assert ax.xaxis._major_tick_kw["label1On"] assert len(ax.get_xticks()) > 0 for l in ax.get_xticklabels(): assert l.get_text() != "" return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(x, y) plt.tick_params(bottom=False, labelbottom=True) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("exercise") # Make catplots of scatter plots by using "time" as x, "pulse" as y, "kind" as hue, and "diet" as col # Change the subplots titles to "Group: Fat" and "Group: No Fat" # SOLUTION START
g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=df) axs = g.axes.flatten() axs[0].set_title("Group: Fat") axs[1].set_title("Group: No Fat")
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("exercise") g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=df) axs = g.axes.flatten() axs[0].set_title("Group: Fat") axs[1].set_title("Group: No Fat") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: axs = plt.gcf().axes assert axs[0].get_title() == "Group: Fat" assert axs[1].get_title() == "Group: No Fat" is_scatter_plot = False for c in axs[0].get_children(): if isinstance(c, matplotlib.collections.PathCollection): is_scatter_plot = True assert is_scatter_plot return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("exercise") [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
654
143
Matplotlib
1
Origin
143
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("exercise") ``` Please help me to: - Make catplots of scatter plots by using "time" as x, "pulse" as y, "kind" as hue, and "diet" as col - Change the subplots titles to "Group: Fat" and "Group: No Fat" - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image import matplotlib def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("exercise") g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=df) axs = g.axes.flatten() axs[0].set_title("Group: Fat") axs[1].set_title("Group: No Fat") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: axs = plt.gcf().axes assert axs[0].get_title() == "Group: Fat" assert axs[1].get_title() == "Group: No Fat" is_scatter_plot = False for c in axs[0].get_children(): if isinstance(c, matplotlib.collections.PathCollection): is_scatter_plot = True assert is_scatter_plot return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("exercise") g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=df) axs = g.axes.flatten() axs[0].set_title("Group: Fat") axs[1].set_title("Group: No Fat") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("exercise") # Make catplots of scatter plots by using "time" as x, "pulse" as y, "kind" as hue, and "diet" as col # Change the xlabels to "Exercise Time" and "Exercise Time" # SOLUTION START
g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=df) axs = g.axes.flatten() axs[0].set_xlabel("Exercise Time") axs[1].set_xlabel("Exercise Time")
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("exercise") g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=df) axs = g.axes.flatten() axs[0].set_xlabel("Exercise Time") axs[1].set_xlabel("Exercise Time") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: axs = plt.gcf().axes assert axs[0].get_xlabel() == "Exercise Time" assert axs[1].get_xlabel() == "Exercise Time" return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("exercise") [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
655
144
Matplotlib
1
Semantic
143
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("exercise") ``` Please help me to: - Make catplots of scatter plots by using "time" as x, "pulse" as y, "kind" as hue, and "diet" as col - Change the xlabels to "Exercise Time" and "Exercise Time" - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("exercise") g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=df) axs = g.axes.flatten() axs[0].set_xlabel("Exercise Time") axs[1].set_xlabel("Exercise Time") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: axs = plt.gcf().axes assert axs[0].get_xlabel() == "Exercise Time" assert axs[1].get_xlabel() == "Exercise Time" return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("exercise") g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=df) axs = g.axes.flatten() axs[0].set_xlabel("Exercise Time") axs[1].set_xlabel("Exercise Time") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("exercise") # Make catplots of scatter plots by using "time" as x, "pulse" as y, "kind" as hue, and "diet" as col # Do not show any ylabel on either subplot # SOLUTION START
g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=df) axs = g.axes.flatten() axs[0].set_ylabel("")
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("exercise") g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=df) axs = g.axes.flatten() axs[0].set_ylabel("") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: axs = plt.gcf().axes assert axs[0].get_ylabel() == "" or axs[0].get_ylabel() is None assert axs[1].get_ylabel() == "" or axs[0].get_ylabel() is None return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("exercise") [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
656
145
Matplotlib
1
Semantic
143
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("exercise") ``` Please help me to: - Make catplots of scatter plots by using "time" as x, "pulse" as y, "kind" as hue, and "diet" as col - Do not show any ylabel on either subplot - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("exercise") g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=df) axs = g.axes.flatten() axs[0].set_ylabel("") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: axs = plt.gcf().axes assert axs[0].get_ylabel() == "" or axs[0].get_ylabel() is None assert axs[1].get_ylabel() == "" or axs[0].get_ylabel() is None return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("exercise") g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=df) axs = g.axes.flatten() axs[0].set_ylabel("") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # plot y over x with label "y" # make the legend fontsize 8 # SOLUTION START
plt.plot(y, x, label="y") plt.legend(fontsize=8)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(y, x, label="y") plt.legend(fontsize=8) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.get_legend()._fontsize == 8 assert len(ax.get_legend().get_texts()) == 1 assert ax.get_legend().get_texts()[0].get_text() == "y" return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
657
146
Matplotlib
1
Origin
146
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - plot y over x with label "y" - make the legend fontsize 8 - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(y, x, label="y") plt.legend(fontsize=8) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.get_legend()._fontsize == 8 assert len(ax.get_legend().get_texts()) == 1 assert ax.get_legend().get_texts()[0].get_text() == "y" return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(y, x, label="y") plt.legend(fontsize=8) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x with figsize (5, 5) and dpi 300 # SOLUTION START
plt.figure(figsize=(5, 5), dpi=300) plt.plot(y, x)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.figure(figsize=(5, 5), dpi=300) plt.plot(y, x) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert (f.get_size_inches() == 5).all() assert float(f.dpi) > 200 # 200 is the default dpi value return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
658
147
Matplotlib
1
Origin
147
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x with figsize (5, 5) and dpi 300 - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.figure(figsize=(5, 5), dpi=300) plt.plot(y, x) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert (f.get_size_inches() == 5).all() assert float(f.dpi) > 200 # 200 is the default dpi value return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.figure(figsize=(5, 5), dpi=300) plt.plot(y, x) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x with label "y" and show legend # Remove the border of frame of legend # SOLUTION START
plt.plot(y, x, label="y") plt.legend(frameon=False)
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(y, x, label="y") plt.legend(frameon=False) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.get_legend().get_texts()) > 0 frame = ax.get_legend().get_frame() assert any( [ not ax.get_legend().get_frame_on(), frame._linewidth == 0, frame._edgecolor == (0, 0, 0, 0), ] ) return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
659
148
Matplotlib
1
Origin
148
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x with label "y" and show legend - Remove the border of frame of legend - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) plt.plot(y, x, label="y") plt.legend(frameon=False) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.get_legend().get_texts()) > 0 frame = ax.get_legend().get_frame() assert any( [ not ax.get_legend().get_frame_on(), frame._linewidth == 0, frame._edgecolor == (0, 0, 0, 0), ] ) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) plt.plot(y, x, label="y") plt.legend(frameon=False) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import math import matplotlib import matplotlib.pyplot as plt t = np.linspace(0, 2 * math.pi, 400) a = np.sin(t) b = np.cos(t) c = a + b # Plot a, b, c in the same figure # SOLUTION START
plt.plot(t, a, t, b, t, c)
import numpy as np import math import matplotlib import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): t = np.linspace(0, 2 * math.pi, 400) a = np.sin(t) b = np.cos(t) c = a + b plt.plot(t, a, t, b, t, c) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() lines = ax.get_lines() assert len(lines) == 3 return 1 exec_context = r""" import numpy as np import math import matplotlib import matplotlib.pyplot as plt t = np.linspace(0, 2 * math.pi, 400) a = np.sin(t) b = np.cos(t) c = a + b [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
660
149
Matplotlib
1
Origin
149
Given this code block: ``` import numpy as np import math import matplotlib import matplotlib.pyplot as plt t = np.linspace(0, 2 * math.pi, 400) a = np.sin(t) b = np.cos(t) c = a + b ``` Please help me to: - Plot a, b, c in the same figure - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import math import matplotlib import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): t = np.linspace(0, 2 * math.pi, 400) a = np.sin(t) b = np.cos(t) c = a + b plt.plot(t, a, t, b, t, c) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() lines = ax.get_lines() assert len(lines) == 3 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import math import matplotlib import matplotlib.pyplot as plt t = np.linspace(0, 2 * math.pi, 400) a = np.sin(t) b = np.cos(t) c = a + b plt.plot(t, a, t, b, t, c) plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[["bill_length_mm", "species", "sex"]] # Make a stripplot for the data in df. Use "sex" as x, "bill_length_mm" as y, and "species" for the color # Remove the legend from the stripplot # SOLUTION START
ax = sns.stripplot(x="sex", y="bill_length_mm", hue="species", data=df) ax.legend_.remove()
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("penguins")[["bill_length_mm", "species", "sex"]] ax = sns.stripplot(x="sex", y="bill_length_mm", hue="species", data=df) ax.legend_.remove() plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert len(f.axes) == 1 ax = plt.gca() assert len(ax.collections) > 0 assert ax.legend_ is None or not ax.legend_._visible assert ax.get_xlabel() == "sex" assert ax.get_ylabel() == "bill_length_mm" all_colors = set() for c in ax.collections: all_colors.add(tuple(c.get_facecolors()[0])) assert len(all_colors) == 1 return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[["bill_length_mm", "species", "sex"]] [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
661
150
Matplotlib
1
Origin
150
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[["bill_length_mm", "species", "sex"]] ``` Please help me to: - Make a stripplot for the data in df. Use "sex" as x, "bill_length_mm" as y, and "species" for the color - Remove the legend from the stripplot - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = sns.load_dataset("penguins")[["bill_length_mm", "species", "sex"]] ax = sns.stripplot(x="sex", y="bill_length_mm", hue="species", data=df) ax.legend_.remove() plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert len(f.axes) == 1 ax = plt.gca() assert len(ax.collections) > 0 assert ax.legend_ is None or not ax.legend_._visible assert ax.get_xlabel() == "sex" assert ax.get_ylabel() == "bill_length_mm" all_colors = set() for c in ax.collections: all_colors.add(tuple(c.get_facecolors()[0])) assert len(all_colors) == 1 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("penguins")[["bill_length_mm", "species", "sex"]] ax = sns.stripplot(x="sex", y="bill_length_mm", hue="species", data=df) ax.legend_.remove() plt.savefig('output.png', bbox_inches ='tight') result = None return result
import seaborn as sns import matplotlib.pylab as plt import pandas import numpy as np df = pandas.DataFrame( { "a": np.arange(1, 31), "b": ["A",] * 10 + ["B",] * 10 + ["C",] * 10, "c": np.random.rand(30), } ) # Use seaborn FaceGrid for rows in "b" and plot seaborn pointplots of "c" over "a" # In each subplot, show xticks of intervals of 1 but show xtick labels with intervals of 2 # SOLUTION START
g = sns.FacetGrid(df, row="b") g.map(sns.pointplot, "a", "c") for ax in g.axes.flat: labels = ax.get_xticklabels() # get x labels for i, l in enumerate(labels): if i % 2 == 0: labels[i] = "" # skip even labels ax.set_xticklabels(labels) # set new labels
import seaborn as sns import matplotlib.pylab as plt import pandas import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = pandas.DataFrame( { "a": np.arange(1, 31), "b": [ "A", ] * 10 + [ "B", ] * 10 + [ "C", ] * 10, "c": np.random.rand(30), } ) g = sns.FacetGrid(df, row="b") g.map(sns.pointplot, "a", "c") for ax in g.axes.flat: labels = ax.get_xticklabels() # get x labels for i, l in enumerate(labels): if i % 2 == 0: labels[i] = "" # skip even labels ax.set_xticklabels(labels) # set new labels plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert len(f.axes) == 3 xticks = f.axes[-1].get_xticks() xticks = np.array(xticks) diff = xticks[1:] - xticks[:-1] assert np.all(diff == 1) xticklabels = [] for label in f.axes[-1].get_xticklabels(): if label.get_text() != "": xticklabels.append(int(label.get_text())) xticklabels = np.array(xticklabels) diff = xticklabels[1:] - xticklabels[:-1] assert np.all(diff == 2) return 1 exec_context = r""" import seaborn as sns import matplotlib.pylab as plt import pandas import numpy as np df = pandas.DataFrame( { "a": np.arange(1, 31), "b": ["A",] * 10 + ["B",] * 10 + ["C",] * 10, "c": np.random.rand(30), } ) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
662
151
Matplotlib
1
Origin
151
Given this code block: ``` import seaborn as sns import matplotlib.pylab as plt import pandas import numpy as np df = pandas.DataFrame( { "a": np.arange(1, 31), "b": ["A",] * 10 + ["B",] * 10 + ["C",] * 10, "c": np.random.rand(30), } ) ``` Please help me to: - Use seaborn FaceGrid for rows in "b" and plot seaborn pointplots of "c" over "a" - In each subplot, show xticks of intervals of 1 but show xtick labels with intervals of 2 - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import seaborn as sns import matplotlib.pylab as plt import pandas import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): df = pandas.DataFrame( { "a": np.arange(1, 31), "b": [ "A", ] * 10 + [ "B", ] * 10 + [ "C", ] * 10, "c": np.random.rand(30), } ) g = sns.FacetGrid(df, row="b") g.map(sns.pointplot, "a", "c") for ax in g.axes.flat: labels = ax.get_xticklabels() # get x labels for i, l in enumerate(labels): if i % 2 == 0: labels[i] = "" # skip even labels ax.set_xticklabels(labels) # set new labels plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert len(f.axes) == 3 xticks = f.axes[-1].get_xticks() xticks = np.array(xticks) diff = xticks[1:] - xticks[:-1] assert np.all(diff == 1) xticklabels = [] for label in f.axes[-1].get_xticklabels(): if label.get_text() != "": xticklabels.append(int(label.get_text())) xticklabels = np.array(xticklabels) diff = xticklabels[1:] - xticklabels[:-1] assert np.all(diff == 2) return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import seaborn as sns import matplotlib.pylab as plt import pandas import numpy as np df = pandas.DataFrame( { "a": np.arange(1, 31), "b": ["A",] * 10 + ["B",] * 10 + ["C",] * 10, "c": np.random.rand(30), } ) g = sns.FacetGrid(df, row="b") g.map(sns.pointplot, "a", "c") for ax in g.axes.flat: labels = ax.get_xticklabels() # get x labels for i, l in enumerate(labels): if i % 2 == 0: labels[i] = "" # skip even labels ax.set_xticklabels(labels) # set new labels plt.savefig('output.png', bbox_inches ='tight') result = None return result
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np x = np.random.random(10) y = np.random.random(10) z = np.random.random(10) # Make a 3D scatter plot of x,y,z # change the view of the plot to have 100 azimuth and 50 elevation # SOLUTION START
fig = plt.figure() ax = fig.add_subplot(111, projection="3d") ax.scatter(x, y, z) ax.azim = 100 ax.elev = 50
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.random.random(10) y = np.random.random(10) z = np.random.random(10) fig = plt.figure() ax = fig.add_subplot(111, projection="3d") ax.scatter(x, y, z) ax.azim = 100 ax.elev = 50 plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.azim == 100 assert ax.elev == 50 assert len(ax.collections) == 1 return 1 exec_context = r""" import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np x = np.random.random(10) y = np.random.random(10) z = np.random.random(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
663
152
Matplotlib
1
Origin
152
Given this code block: ``` import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np x = np.random.random(10) y = np.random.random(10) z = np.random.random(10) ``` Please help me to: - Make a 3D scatter plot of x,y,z - change the view of the plot to have 100 azimuth and 50 elevation - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import matplotlib.pyplot as plt import numpy as np from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.random.random(10) y = np.random.random(10) z = np.random.random(10) fig = plt.figure() ax = fig.add_subplot(111, projection="3d") ax.scatter(x, y, z) ax.azim = 100 ax.elev = 50 plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert ax.azim == 100 assert ax.elev == 50 assert len(ax.collections) == 1 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np x = np.random.random(10) y = np.random.random(10) z = np.random.random(10) fig = plt.figure() ax = fig.add_subplot(111, projection="3d") ax.scatter(x, y, z) ax.azim = 100 ax.elev = 50 plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # Plot y over x in a line chart and name axis with labels ("x" and "y") # Hide tick labels but keep axis labels # SOLUTION START
fig, ax = plt.subplots() ax.plot(x, y) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_xlabel("x") ax.set_ylabel("y")
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) fig, ax = plt.subplots() ax.plot(x, y) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_xlabel("x") ax.set_ylabel("y") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.get_lines()) > 0 no_tick_label = np.all( [l._text == "" for l in ax.get_xaxis().get_majorticklabels()] ) tick_not_visible = not ax.get_xaxis()._visible ax.get_xaxis() assert no_tick_label or tick_not_visible assert ax.get_xaxis().get_label().get_text() == "x" assert ax.get_yaxis().get_label().get_text() == "y" return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
664
153
Matplotlib
1
Origin
153
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) ``` Please help me to: - Plot y over x in a line chart and name axis with labels ("x" and "y") - Hide tick labels but keep axis labels - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.arange(10) y = np.arange(10) fig, ax = plt.subplots() ax.plot(x, y) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_xlabel("x") ax.set_ylabel("y") plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: ax = plt.gca() assert len(ax.get_lines()) > 0 no_tick_label = np.all( [l._text == "" for l in ax.get_xaxis().get_majorticklabels()] ) tick_not_visible = not ax.get_xaxis()._visible ax.get_xaxis() assert no_tick_label or tick_not_visible assert ax.get_xaxis().get_label().get_text() == "x" assert ax.get_yaxis().get_label().get_text() == "y" return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) fig, ax = plt.subplots() ax.plot(x, y) ax.set_xticklabels([]) ax.set_yticklabels([]) ax.set_xlabel("x") ax.set_ylabel("y") plt.savefig('output.png', bbox_inches ='tight') result = None return result
import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.random.random((10, 10)) from matplotlib import gridspec nrow = 2 ncol = 2 fig = plt.figure(figsize=(ncol + 1, nrow + 1)) # Make a 2x2 subplots with fig and plot x in each subplot as an image # Remove the space between each subplot and make the subplot adjacent to each other # Remove the axis ticks from each subplot # SOLUTION START
gs = gridspec.GridSpec( nrow, ncol, wspace=0.0, hspace=0.0, top=1.0 - 0.5 / (nrow + 1), bottom=0.5 / (nrow + 1), left=0.5 / (ncol + 1), right=1 - 0.5 / (ncol + 1), ) for i in range(nrow): for j in range(ncol): ax = plt.subplot(gs[i, j]) ax.imshow(x) ax.set_xticklabels([]) ax.set_yticklabels([])
import numpy as np import pandas as pd import matplotlib.pyplot as plt from matplotlib import gridspec from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.random.random((10, 10)) nrow = 2 ncol = 2 fig = plt.figure(figsize=(ncol + 1, nrow + 1)) gs = gridspec.GridSpec( nrow, ncol, wspace=0.0, hspace=0.0, top=1.0 - 0.5 / (nrow + 1), bottom=0.5 / (nrow + 1), left=0.5 / (ncol + 1), right=1 - 0.5 / (ncol + 1), ) for i in range(nrow): for j in range(ncol): ax = plt.subplot(gs[i, j]) ax.imshow(x) ax.set_xticklabels([]) ax.set_yticklabels([]) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert len(f.axes) == 4 for ax in f.axes: assert len(ax.images) == 1 assert ax.get_subplotspec()._gridspec.hspace == 0.0 assert ax.get_subplotspec()._gridspec.wspace == 0.0 return 1 exec_context = r""" import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.random.random((10, 10)) from matplotlib import gridspec nrow = 2 ncol = 2 fig = plt.figure(figsize=(ncol + 1, nrow + 1)) [insert] plt.savefig('output.png', bbox_inches ='tight') result = None """ def test_execution(solution: str): solution = "\n".join(filter(skip_plt_cmds, solution.split("\n"))) code = exec_context.replace("[insert]", solution) for i in range(1): test_input, expected_result = generate_test_case(i + 1) test_env = {"test_input": test_input} exec(code, test_env) assert exec_test(test_env["result"], expected_result)
665
154
Matplotlib
1
Origin
154
Given this code block: ``` import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.random.random((10, 10)) from matplotlib import gridspec nrow = 2 ncol = 2 fig = plt.figure(figsize=(ncol + 1, nrow + 1)) ``` Please help me to: - Make a 2x2 subplots with fig and plot x in each subplot as an image - Remove the space between each subplot and make the subplot adjacent to each other - Remove the axis ticks from each subplot - save the figure using `plt.savefig('output.png', bbox_inches ='tight')` I need the solution to fit in a function with the following signature: ``` def solve(input): # Receives "input" a single variable. If the solution requires more than one input parameter, treat the input as a list: `a,b,c = input`. # Returns only the solution, a modified entity or None ```
import numpy as np import pandas as pd import matplotlib.pyplot as plt from matplotlib import gridspec from PIL import Image def skip_plt_cmds(l): return all( p not in l for p in ["plt.show()", "plt.clf()", "plt.close()", "savefig"] ) def generate_test_case(test_case_id): x = np.random.random((10, 10)) nrow = 2 ncol = 2 fig = plt.figure(figsize=(ncol + 1, nrow + 1)) gs = gridspec.GridSpec( nrow, ncol, wspace=0.0, hspace=0.0, top=1.0 - 0.5 / (nrow + 1), bottom=0.5 / (nrow + 1), left=0.5 / (ncol + 1), right=1 - 0.5 / (ncol + 1), ) for i in range(nrow): for j in range(ncol): ax = plt.subplot(gs[i, j]) ax.imshow(x) ax.set_xticklabels([]) ax.set_yticklabels([]) plt.savefig("ans.png", bbox_inches="tight") plt.close() return None, None def exec_test(result, ans): code_img = np.array(Image.open("output.png")) oracle_img = np.array(Image.open("ans.png")) sample_image_stat = code_img.shape == oracle_img.shape and np.allclose( code_img, oracle_img ) if not sample_image_stat: f = plt.gcf() assert len(f.axes) == 4 for ax in f.axes: assert len(ax.images) == 1 assert ax.get_subplotspec()._gridspec.hspace == 0.0 assert ax.get_subplotspec()._gridspec.wspace == 0.0 return 1 def test_execution(): for i in range(1): test_input, expected_result = generate_test_case(i + 1) this_result = solve(test_input) assert exec_test(this_result, expected_result) test_execution()
def solve(test_input): import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.random.random((10, 10)) from matplotlib import gridspec nrow = 2 ncol = 2 fig = plt.figure(figsize=(ncol + 1, nrow + 1)) gs = gridspec.GridSpec( nrow, ncol, wspace=0.0, hspace=0.0, top=1.0 - 0.5 / (nrow + 1), bottom=0.5 / (nrow + 1), left=0.5 / (ncol + 1), right=1 - 0.5 / (ncol + 1), ) for i in range(nrow): for j in range(ncol): ax = plt.subplot(gs[i, j]) ax.imshow(x) ax.set_xticklabels([]) ax.set_yticklabels([]) plt.savefig('output.png', bbox_inches ='tight') result = None return result