id
stringlengths
9
9
text
stringlengths
312
2.4k
title
stringclasses
1 value
000001900
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns x = np.arange(10) y = np.random.randn(10) plt.scatter(x, y) # show yticks and horizontal grid at y positions 3 and 4 # SOLUTION START ax = plt.gca() ax.yaxis.set_ticks([3, 4]) ax.yaxis.grid(True) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() xlines = ax.get_xaxis() l = xlines.get_gridlines()[0] assert not l.get_visible() np.testing.assert_equal([3, 4], ax.get_yticks()) ylines = ax.get_yaxis() l = ylines.get_gridlines()[0] assert l.get_visible() with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001901
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns x = np.linspace(0, 2 * np.pi, 10) y = np.cos(x) plt.plot(x, y, label="sin") # put a x axis ticklabels at 0, 2, 4... # SOLUTION START minx = x.min() maxx = x.max() plt.xticks(np.arange(minx, maxx, step=2)) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() plt.show() x = ax.get_xaxis() ticks = ax.get_xticks() labels = ax.get_xticklabels() for t, l in zip(ticks, ax.get_xticklabels()): assert int(t) % 2 == 0 assert l.get_text() == str(int(t)) assert all(sorted(ticks) == ticks) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001902
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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]) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing import matplotlib for c in plt.gca().get_children(): if isinstance(c, matplotlib.image.AxesImage): break assert c.get_extent() == [1, 5, 1, 4] with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001903
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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()) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() import matplotlib 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" ) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001904
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(2010, 2020) y = np.arange(10) plt.plot(x, y) # Set the transparency of xtick labels to be 0.5 # SOLUTION START plt.yticks(alpha=0.5) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() for l in ax.get_yticklabels(): assert l._alpha == 0.5 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001905
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing axs = plt.gcf().axes assert axs[0].get_title() == "Group: Fat" assert axs[1].get_title() == "Group: No Fat" import matplotlib 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 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001906
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import matplotlib.pyplot as plt import numpy as np x = np.random.random((10, 10)) y = np.random.random((10, 10)) # make two colormaps with x and y and put them into different subplots # use a single colorbar for these two subplots # SOLUTION START fig, axes = plt.subplots(nrows=1, ncols=2) axes[0].imshow(x, vmin=0, vmax=1) im = axes[1].imshow(x, vmin=0, vmax=1) fig.subplots_adjust(right=0.8) cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7]) fig.colorbar(im, cax=cbar_ax) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() plt.show() assert len(f.get_children()) == 4 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001907
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.collections) == 1 ax.collections[0].get_cmap().name == "Spectral" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001908
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import matplotlib.pyplot as plt import numpy as np, pandas as pd import seaborn as sns tips = sns.load_dataset("tips") # Make a seaborn joint regression plot (kind='reg') of 'total_bill' and 'tip' in the tips dataframe # change the line color in the regression to green but keep the histograms in blue # SOLUTION START sns.jointplot( x="total_bill", y="tip", data=tips, kind="reg", line_kws={"color": "green"} ) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() assert len(f.axes) == 3 assert len(f.axes[0].get_lines()) == 1 assert f.axes[0].get_xlabel() == "total_bill" assert f.axes[0].get_ylabel() == "tip" assert f.axes[0].get_lines()[0]._color in ["green", "g", "#008000"] for p in f.axes[1].patches: assert p.get_facecolor()[0] != 0 assert p.get_facecolor()[2] != 0 for p in f.axes[2].patches: assert p.get_facecolor()[0] != 0 assert p.get_facecolor()[2] != 0 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001909
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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"}) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.texts) == 4 for t in ax.texts: assert "bold" in t.get_fontweight() with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001910
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(2010, 2020) y = np.arange(10) plt.plot(x, y) # Rotate the yticklabels to -60 degree. Set the xticks vertical alignment to top. # SOLUTION START plt.yticks(rotation=-60) plt.yticks(va="top") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() for l in ax.get_yticklabels(): assert l._verticalalignment == "top" assert l._rotation == -60 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001911
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing import matplotlib 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) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001912
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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), ] ) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001913
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 # move the y axis ticks to the right # SOLUTION START f = plt.figure() ax = f.add_subplot(111) ax.plot(x, y) ax.yaxis.tick_right() # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.yaxis.get_ticks_position() == "right" assert ax.yaxis._major_tick_kw["tick2On"] assert not ax.yaxis._major_tick_kw["tick1On"] with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001914
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import matplotlib.pyplot as plt import numpy as np, pandas as pd import seaborn as sns tips = sns.load_dataset("tips") # Make a seaborn joint regression plot (kind='reg') of 'total_bill' and 'tip' in the tips dataframe # change the line and scatter plot color to green but keep the distribution plot in blue # SOLUTION START sns.jointplot( x="total_bill", y="tip", data=tips, kind="reg", joint_kws={"color": "green"} ) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() assert len(f.axes) == 3 assert len(f.axes[0].get_lines()) == 1 assert f.axes[0].get_lines()[0]._color in ["green", "g", "#008000"] assert f.axes[0].collections[0].get_facecolor()[0][2] == 0 for p in f.axes[1].patches: assert p.get_facecolor()[0] != 0 assert p.get_facecolor()[2] != 0 for p in f.axes[2].patches: assert p.get_facecolor()[0] != 0 assert p.get_facecolor()[2] != 0 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001915
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 different subplots # Set "Y and Z" as a main title above the two subplots # SOLUTION START fig, axes = plt.subplots(nrows=1, ncols=2) axes[0].plot(x, y) axes[1].plot(a, z) plt.suptitle("Y and Z") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() assert f._suptitle.get_text() == "Y and Z" for ax in f.axes: assert ax.get_title() == "" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001916
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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() # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.get_xlim()[0] > ax.get_xlim()[1] with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001917
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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"]) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001918
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 label the x axis as "X" # Make the line of the x axis red # SOLUTION START fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x, y) ax.set_xlabel("X") ax.spines["bottom"].set_color("red") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() plt.show() assert ax.spines["bottom"].get_edgecolor() == "red" or ax.spines[ "bottom" ].get_edgecolor() == (1.0, 0.0, 0.0, 1.0) assert ax.spines["top"].get_edgecolor() != "red" and ax.spines[ "top" ].get_edgecolor() != (1.0, 0.0, 0.0, 1.0) assert ax.spines["left"].get_edgecolor() != "red" and ax.spines[ "left" ].get_edgecolor() != (1.0, 0.0, 0.0, 1.0) assert ax.spines["right"].get_edgecolor() != "red" and ax.spines[ "right" ].get_edgecolor() != (1.0, 0.0, 0.0, 1.0) assert ax.xaxis.label._color != "red" and ax.xaxis.label._color != (1.0, 0.0, 0.0, 1.0) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001919
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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.xticks(range(0, 10, 2)) # Add extra ticks [2.1, 3, 7.6] to existing xticks # SOLUTION START plt.xticks(list(plt.xticks()[0]) + [2.1, 3, 7.6]) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() plt.savefig("tempfig.png") all_ticks = [ax.get_loc() for ax in ax.xaxis.get_major_ticks()] assert len(all_ticks) == 8 for i in [2.1, 3.0, 7.6]: assert i in all_ticks with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001920
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.azim == 100 assert ax.elev == 50 assert len(ax.collections) == 1 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001921
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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)) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.patches) == 5 for i in range(5): assert ax.patches[i].get_width() == 2.0 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001922
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001923
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 ) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001924
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt x = np.arange(10) y = np.sin(x) # draw a line plot of x vs y using seaborn and pandas # SOLUTION START df = pd.DataFrame({"x": x, "y": y}) sns.lineplot(x="x", y="y", data=df) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.lines) == 1 np.testing.assert_allclose(ax.lines[0].get_data()[0], x) np.testing.assert_allclose(ax.lines[0].get_data()[1], y) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001925
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns x = np.arange(10) y = np.random.randn(10) # line plot x and y with a thin diamond marker # SOLUTION START plt.plot(x, y, marker="d") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing # there should be lines each having a different style ax = plt.gca() assert ax.lines[0].get_marker() == "d" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001926
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() assert (f.get_size_inches() == 5).all() assert float(f.dpi) > 200 # 200 is the default dpi value with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001927
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 font size 20 for title, font size 18 for xlabel and font size 16 for ylabel # SOLUTION START plt.plot(x, y, label="1") plt.title("test title", fontsize=20) plt.xlabel("xlabel", fontsize=18) plt.ylabel("ylabel", fontsize=16) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() ylabel_font = ax.yaxis.get_label().get_fontsize() xlabel_font = ax.xaxis.get_label().get_fontsize() title_font = ax.title.get_fontsize() assert ylabel_font != xlabel_font assert title_font != xlabel_font assert title_font != ylabel_font with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001928
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import matplotlib.pyplot as plt import numpy as np, pandas as pd import seaborn as sns tips = sns.load_dataset("tips") # Make a seaborn joint regression plot (kind='reg') of 'total_bill' and 'tip' in the tips dataframe # do not use scatterplot for the joint plot # SOLUTION START sns.jointplot( x="total_bill", y="tip", data=tips, kind="reg", joint_kws={"scatter": False} ) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() assert len(f.axes) == 3 assert len(f.axes[0].get_lines()) == 1 assert len(f.axes[0].collections) == 1 assert f.axes[0].get_xlabel() == "total_bill" assert f.axes[0].get_ylabel() == "tip" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001929
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.random.rand(10) y = np.random.rand(10) # Plot a grouped histograms of x and y on a single chart with matplotlib # Use grouped histograms so that the histograms don't overlap with each other # SOLUTION START bins = np.linspace(-1, 1, 100) plt.hist([x, y]) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() all_xs = [] all_widths = [] assert len(ax.patches) > 0 for p in ax.patches: all_xs.append(p.get_x()) all_widths.append(p.get_width()) all_xs = np.array(all_xs) all_widths = np.array(all_widths) sort_ids = all_xs.argsort() all_xs = all_xs[sort_ids] all_widths = all_widths[sort_ids] assert np.all(all_xs[1:] - (all_xs + all_widths)[:-1] > -0.001) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001930
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import matplotlib.pyplot as plt from matplotlib import rc rc("mathtext", default="regular") time = np.arange(10) temp = np.random.random(10) * 30 Swdown = np.random.random(10) * 100 - 10 Rn = np.random.random(10) * 100 - 10 fig = plt.figure() ax = fig.add_subplot(111) ax.plot(time, Swdown, "-", label="Swdown") ax.plot(time, Rn, "-", label="Rn") ax2 = ax.twinx() ax2.plot(time, temp, "-r", label="temp") ax.legend(loc=0) ax.grid() ax.set_xlabel("Time (h)") ax.set_ylabel(r"Radiation ($MJ\,m^{-2}\,d^{-1}$)") ax2.set_ylabel(r"Temperature ($^\circ$C)") ax2.set_ylim(0, 35) ax.set_ylim(-20, 100) plt.show() plt.clf() # copy the code of the above plot and edit it to have legend for all three cruves in the two subplots # SOLUTION START fig = plt.figure() ax = fig.add_subplot(111) ax.plot(time, Swdown, "-", label="Swdown") ax.plot(time, Rn, "-", label="Rn") ax2 = ax.twinx() ax2.plot(time, temp, "-r", label="temp") ax.legend(loc=0) ax.grid() ax.set_xlabel("Time (h)") ax.set_ylabel(r"Radiation ($MJ\,m^{-2}\,d^{-1}$)") ax2.set_ylabel(r"Temperature ($^\circ$C)") ax2.set_ylim(0, 35) ax.set_ylim(-20, 100) ax2.legend(loc=0) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() plt.show() assert len(f.axes) == 2 assert len(f.axes[0].get_lines()) == 2 assert len(f.axes[1].get_lines()) == 1 assert len(f.axes[0]._twinned_axes.get_siblings(f.axes[0])) == 2 if len(f.legends) == 1: assert len(f.legends[0].get_texts()) == 3 elif len(f.legends) > 1: assert False else: assert len(f.axes[0].get_legend().get_texts()) == 2 assert len(f.axes[1].get_legend().get_texts()) == 1 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001931
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import matplotlib.pyplot as plt import numpy as np x = np.arange(10) y = np.arange(10) f = plt.figure() ax = f.add_subplot(111) # plot y over x, show tick labels (from 1 to 10) # use the `ax` object to set the tick labels # SOLUTION START plt.plot(x, y) ax.set_xticks(np.arange(1, 11)) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert np.allclose(ax.get_xticks(), np.arange(1, 11)) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001932
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 remove the edge of the marker # Use vertical line hatch for the marker # SOLUTION START plt.scatter(x, y, linewidth=0, hatch="|") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() lw_flag = True for l in ax.collections[0].get_linewidth(): if l != 0: lw_flag = False assert lw_flag assert ax.collections[0].get_hatch() is not None assert "|" in ax.collections[0].get_hatch()[0] with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001933
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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"}) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.texts) == 4 for t in ax.texts: assert "bold" in t.get_fontweight() with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001934
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() assert len(f.axes) == 3 xticks = f.axes[-1].get_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) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001935
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10, 20) z = np.arange(10) import matplotlib.pyplot as plt plt.plot(x, y) plt.plot(x, z) # Give names to the lines in the above plot 'Y' and 'Z' and show them in a legend # SOLUTION START plt.plot(x, y, label="Y") plt.plot(x, z, label="Z") plt.legend() # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert tuple([t._text for t in ax.get_legend().get_texts()]) == ("Y", "Z") with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001936
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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"] ] # Make 2 subplots. # In the first subplot, plot a seaborn regression plot of "bill_depth_mm" over "bill_length_mm" # In the second subplot, plot a seaborn regression plot of "flipper_length_mm" over "bill_length_mm" # Do not share y axix for the subplots # SOLUTION START f, ax = plt.subplots(1, 2, figsize=(12, 6)) sns.regplot(x="bill_length_mm", y="bill_depth_mm", data=df, ax=ax[0]) sns.regplot(x="bill_length_mm", y="flipper_length_mm", data=df, ax=ax[1]) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() assert len(f.axes) == 2 assert len(f.axes[0]._shared_axes["x"].get_siblings(f.axes[0])) == 1 for ax in f.axes: assert len(ax.collections) == 2 assert len(ax.get_lines()) == 1 assert ax.get_xlabel() == "bill_length_mm" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001937
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns x = np.random.randn(10) y = x plt.scatter(x, y) # put x ticks at 0 and 1.5 only # SOLUTION START ax = plt.gca() ax.set_xticks([0, 1.5]) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() np.testing.assert_equal([0, 1.5], ax.get_xticks()) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001938
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import matplotlib.pyplot as plt import numpy as np column_labels = list("ABCD") row_labels = list("WXYZ") data = np.random.rand(4, 4) fig, ax = plt.subplots() heatmap = ax.pcolor(data, cmap=plt.cm.Blues) # Move the x-axis of this heatmap to the top of the plot # SOLUTION START ax.xaxis.tick_top() # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.xaxis._major_tick_kw["tick2On"] assert ax.xaxis._major_tick_kw["label2On"] assert not ax.xaxis._major_tick_kw["tick1On"] assert not ax.xaxis._major_tick_kw["label1On"] with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001939
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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", "--", "-.", ":"] with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001940
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001941
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import matplotlib.pyplot as plt lines = [[(0, 1), (1, 1)], [(2, 3), (3, 3)], [(1, 2), (1, 3)]] c = np.array([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)]) # Plot line segments according to the positions specified in lines # Use the colors specified in c to color each line segment # SOLUTION START for i in range(len(lines)): plt.plot([lines[i][0][0], lines[i][1][0]], [lines[i][0][1], lines[i][1][1]], c=c[i]) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.get_lines()) == len(lines) for i in range(len(lines)): assert np.all(ax.get_lines()[i].get_color() == c[i]) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001942
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import numpy as np import matplotlib.pyplot as plt x = np.random.rand(10) y = np.random.rand(10) z = np.random.rand(10) # plot x, then y then z, but so that x covers y and y covers z # SOLUTION START plt.plot(x, zorder=10) plt.plot(y, zorder=5) plt.plot(z, zorder=1) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() ls = ax.lines assert len(ls) == 3 zorder = [i.zorder for i in ls] np.testing.assert_equal(zorder, sorted(zorder, reverse=True)) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001943
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001944
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns x = np.arange(10) y = np.random.randn(10) plt.scatter(x, y) # show xticks and vertical grid at x positions 3 and 4 # SOLUTION START ax = plt.gca() # ax.set_yticks([-1, 1]) ax.xaxis.set_ticks([3, 4]) ax.xaxis.grid(True) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() np.testing.assert_equal([3, 4], ax.get_xticks()) xlines = ax.get_xaxis() l = xlines.get_gridlines()[0] assert l.get_visible() ylines = ax.get_yaxis() l = ylines.get_gridlines()[0] assert not l.get_visible() with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001945
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt a = [2.56422, 3.77284, 3.52623] b = [0.15, 0.3, 0.45] c = [58, 651, 393] # make scatter plot of a over b and annotate each data point with correspond numbers in c # SOLUTION START fig, ax = plt.subplots() plt.scatter(a, b) for i, txt in enumerate(c): ax.annotate(txt, (a[i], b[i])) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.texts) == 3 for t in ax.texts: assert int(t.get_text()) in c with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001946
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 tick font size 10 and make the x tick labels vertical # SOLUTION START plt.plot(y, x) plt.xticks(fontsize=10, rotation=90) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.xaxis._get_tick_label_size("x") == 10 assert ax.xaxis.get_ticklabels()[0]._rotation in [90, 270, "vertical"] with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001947
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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("") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001948
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 label y axis "Y" # Show y axis ticks on the left and y axis label on the right # SOLUTION START plt.plot(x, y) plt.ylabel("y") ax = plt.gca() ax.yaxis.set_label_position("right") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.yaxis.get_label_position() == "right" assert not ax.yaxis._major_tick_kw["tick2On"] assert ax.yaxis._major_tick_kw["tick1On"] with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001949
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 # do not show xticks for the plot # SOLUTION START plt.plot(y, x) plt.tick_params( axis="x", # changes apply to the x-axis which="both", # both major and minor ticks are affected bottom=False, # ticks along the bottom edge are off top=False, # ticks along the top edge are off labelbottom=False, ) # labels along the bottom edge are off # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() plt.show() label_off = not any(ax.xaxis._major_tick_kw.values()) axis_off = not ax.axison no_ticks = len(ax.get_xticks()) == 0 assert any([label_off, axis_off, no_ticks]) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001950
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 # Use vertical line hatch for the marker and make the hatch dense # SOLUTION START plt.scatter(x, y, hatch="||||") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.collections[0].get_hatch() is not None assert "|" in ax.collections[0].get_hatch()[0] assert len(ax.collections[0].get_hatch()) > 1 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001951
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.patches) == 1 import matplotlib 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) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001952
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns df = sns.load_dataset("planets") g = sns.boxplot(x="method", y="orbital_period", data=df) # rotate the x axis labels by 90 degrees # SOLUTION START ax = plt.gca() ax.set_xticklabels(ax.get_xticklabels(), rotation=90) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() xaxis = ax.get_xaxis() ticklabels = xaxis.get_ticklabels() assert len(ticklabels) > 0 for t in ticklabels: assert 90 == t.get_rotation() with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001953
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.collections) == 1 for seg in ax.collections[0].get_segments(): assert seg[0][0] == 0 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001954
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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() != "" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001955
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns data = { "reports": [4, 24, 31, 2, 3], "coverage": [35050800, 54899767, 57890789, 62890798, 70897871], } df = pd.DataFrame(data) sns.factorplot(y="coverage", x="reports", kind="bar", data=df, label="Total") # do not use scientific notation in the y axis ticks labels # SOLUTION START plt.ticklabel_format(style="plain", axis="y") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() plt.show() assert len(ax.get_yticklabels()) > 0 for l in ax.get_yticklabels(): if int(l.get_text()) > 0: assert int(l.get_text()) > 1000 assert "e" not in l.get_text() with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001956
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.random.rand(10) y = np.random.rand(10) bins = np.linspace(-1, 1, 100) # Plot two histograms of x and y on a single chart with matplotlib # Set the transparency of the histograms to be 0.5 # SOLUTION START plt.hist(x, bins, alpha=0.5, label="x") plt.hist(y, bins, alpha=0.5, label="y") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.patches) > 0 for p in ax.patches: assert p.get_alpha() == 0.5 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001957
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 plot # Show marker on the line plot. Make the marker have a 0.5 transparency but keep the lines solid. # SOLUTION START (l,) = plt.plot(x, y, "o-", lw=10, markersize=30) l.set_markerfacecolor((1, 1, 0, 0.5)) l.set_color("blue") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() lines = ax.get_lines() assert len(lines) == 1 assert lines[0].get_markerfacecolor() assert not isinstance(lines[0].get_markerfacecolor(), str) assert lines[0].get_markerfacecolor()[-1] == 0.5 assert isinstance(lines[0].get_color(), str) or lines[0].get_color()[-1] == 1 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001958
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns x = np.random.randn(10) y = np.random.randn(10) sns.distplot(x, label="a", color="0.25") sns.distplot(y, label="b", color="0.25") # add legends # SOLUTION START plt.legend() # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.legend_ is not None, "there should be a legend" assert ax.legend_._visible with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001959
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.arange(10) y = np.arange(10) # make a two columns and one row subplots. Plot y over x in each subplot. # Give the plot a global title "Figure" # SOLUTION START fig = plt.figure(constrained_layout=True) axs = fig.subplots(1, 2) for ax in axs.flat: ax.plot(x, y) fig.suptitle("Figure") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() assert f.axes[0].get_gridspec().ncols == 2 assert f.axes[0].get_gridspec().nrows == 1 assert f._suptitle.get_text() == "Figure" for ax in f.axes: assert ax.get_title() == "" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001960
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 # Show legend and use the greek letter lambda as the legend label # SOLUTION START plt.plot(y, x, label=r"$\lambda$") plt.legend() # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.get_legend().get_texts()[0].get_text() == "$\\lambda$" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001961
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns # draw a full line from (0,0) to (1,2) # SOLUTION START p1 = (0, 0) p2 = (1, 2) plt.axline(p1, p2) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing import matplotlib ax = plt.gca() assert len(ax.get_lines()) == 1 assert isinstance(ax.get_lines()[0], matplotlib.lines._AxLine) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001962
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001963
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns x = np.linspace(0, 2 * np.pi, 10) y = np.cos(x) # set xlabel as "X" # put the x label at the right end of the x axis # SOLUTION START plt.plot(x, y) ax = plt.gca() label = ax.set_xlabel("X", fontsize=9) ax.xaxis.set_label_coords(1, 0) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() label = ax.xaxis.get_label() assert label.get_text() == "X" assert label.get_position()[0] > 0.8 assert label.get_position()[0] < 1.5 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001964
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.get_legend().numpoints == 2 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001965
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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}$") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert "\\phi" in ax.get_title() assert "bf" in ax.get_title() assert "$" in ax.get_title() with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001966
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() assert (f.get_size_inches() == (15, 15)).all() for ax in f.axes: assert len(ax.get_lines()) == 1 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001967
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt y = 2 * np.random.rand(10) x = np.arange(10) plt.plot(x, y) myTitle = "Some really really long long long title I really really need - and just can't - just can't - make it any - simply any - shorter - at all." # fit a very long title myTitle into multiple lines # SOLUTION START # set title # plt.title(myTitle, loc='center', wrap=True) from textwrap import wrap ax = plt.gca() ax.set_title("\n".join(wrap(myTitle, 60)), loc="center", wrap=True) # axes.set_title("\n".join(wrap(myTitle, 60)), loc='center', wrap=True) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing fg = plt.gcf() assert fg.get_size_inches()[0] < 8 ax = plt.gca() assert ax.get_title().startswith(myTitle[:10]) assert "\n" in ax.get_title() assert len(ax.get_title()) >= len(myTitle) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001968
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns x = np.arange(10) y = 2 * np.random.rand(10) # draw a regular matplotlib style plot using seaborn # SOLUTION START sns.lineplot(x=x, y=y) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() l = ax.lines[0] xp, yp = l.get_xydata().T np.testing.assert_array_almost_equal(xp, x) np.testing.assert_array_almost_equal(yp, y) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001969
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns x = np.arange(10) # draw a line (with random y) for each different line style # SOLUTION START from matplotlib import lines styles = lines.lineStyles.keys() nstyles = len(styles) for i, sty in enumerate(styles): y = np.random.randn(*x.shape) plt.plot(x, y, sty) # print(lines.lineMarkers.keys()) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing # there should be lines each having a different style ax = plt.gca() from matplotlib import lines assert len(lines.lineStyles.keys()) == len(ax.lines) allstyles = lines.lineStyles.keys() for l in ax.lines: sty = l.get_linestyle() assert sty in allstyles with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001970
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import matplotlib.pyplot as plt H = np.random.randn(10, 10) # color plot of the 2d array H # SOLUTION START plt.imshow(H, interpolation="none") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.images) == 1 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001971
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.random.randn(10) y = np.random.randn(10) # in plt.plot(x, y), use a plus marker and give it a thickness of 7 # SOLUTION START plt.plot(x, y, "+", mew=7, ms=20) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.lines) == 1 assert ax.lines[0].get_markeredgewidth() == 7 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001972
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns x = np.random.rand(10) y = np.random.rand(10) plt.scatter(x, y) # how to turn on minor ticks on x axis only # SOLUTION START plt.minorticks_on() ax = plt.gca() ax.tick_params(axis="y", which="minor", tick1On=False) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing # x axis has no minor ticks # y axis has minor ticks ax = plt.gca() assert len(ax.collections) == 1 xticks = ax.xaxis.get_minor_ticks() assert len(xticks) > 0, "there should be some x ticks" for t in xticks: assert t.tick1line.get_visible(), "x tick1lines should be visible" yticks = ax.yaxis.get_minor_ticks() for t in yticks: assert not t.tick1line.get_visible(), "y tick1line should not be visible" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001973
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 label the line "y over x" # Show legend of the plot and give the legend box a title # SOLUTION START plt.plot(x, y, label="y over x") plt.legend(title="legend") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.get_legend().get_texts()) > 0 assert len(ax.get_legend().get_title().get_text()) > 0 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001974
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 # Use star hatch for the marker # SOLUTION START plt.scatter(x, y, hatch="*") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.collections[0].get_hatch() is not None assert "*" in ax.collections[0].get_hatch()[0] with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001975
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.get_legend()._ncol == 2 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001976
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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() # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001977
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import matplotlib.pyplot as plt # draw vertical lines at [0.22058956, 0.33088437, 2.20589566] # SOLUTION START plt.axvline(x=0.22058956) plt.axvline(x=0.33088437) plt.axvline(x=2.20589566) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing data = [0.22058956, 0.33088437, 2.20589566] ax = plt.gca() assert len(ax.lines) == 3 for l in ax.lines: assert l.get_xdata()[0] in data with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001978
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns x = np.linspace(0, 2 * np.pi, 400) y1 = np.sin(x) y2 = np.cos(x) # plot x vs y1 and x vs y2 in two subplots, sharing the x axis # SOLUTION START fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True) plt.subplots_adjust(hspace=0.0) ax1.grid() ax2.grid() ax1.plot(x, y1, color="r") ax2.plot(x, y2, color="b", linestyle="--") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing fig = plt.gcf() ax12 = fig.axes assert len(ax12) == 2 ax1, ax2 = ax12 x1 = ax1.get_xticks() x2 = ax2.get_xticks() np.testing.assert_equal(x1, x2) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001979
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() from numpy import * import math import matplotlib import matplotlib.pyplot as plt t = linspace(0, 2 * math.pi, 400) a = sin(t) b = cos(t) c = a + b # Plot a, b, c in the same figure # SOLUTION START plt.plot(t, a, t, b, t, c) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() lines = ax.get_lines() assert len(lines) == 3 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001980
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns x = np.arange(10) y = np.sin(x) df = pd.DataFrame({"x": x, "y": y}) sns.lineplot(x="x", y="y", data=df) # remove x tick labels # SOLUTION START ax = plt.gca() ax.set(xticklabels=[]) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() lbl = ax.get_xticklabels() ticks = ax.get_xticks() for t, tk in zip(lbl, ticks): assert t.get_position()[0] == tk, "tick might not been set, so the default was used" assert t.get_text() == "", "the text should be non-empty" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001981
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import matplotlib.pyplot as plt import pandas as pd import numpy as np df = pd.DataFrame( np.random.randn(50, 4), index=pd.date_range("1/1/2000", periods=50), columns=list("ABCD"), ) df = df.cumsum() # make four line plots of data in the data frame # show the data points on the line plot # SOLUTION START df.plot(style=".-") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.get_lines()[0].get_linestyle() != "None" assert ax.get_lines()[0].get_marker() != "None" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001982
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt x = np.random.randn(10) y = np.random.randn(10) # in a scatter plot of x, y, make the points have black borders and blue face # SOLUTION START plt.scatter(x, y, c="blue", edgecolors="black") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.collections) == 1 edgecolors = ax.collections[0].get_edgecolors() assert edgecolors.shape[0] == 1 assert np.allclose(edgecolors[0], [0.0, 0.0, 0.0, 1.0]) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001983
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing axs = plt.gcf().axes assert axs[0].get_xlabel() == "Exercise Time" assert axs[1].get_xlabel() == "Exercise Time" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001984
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 factorpot 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.factorplot( x="sex", col="species", y="bill_length_mm", data=df, kind="bar", sharey=False ) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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() ) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001985
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt points = [(3, 5), (5, 10), (10, 150)] # plot a line plot for points in points. # Make the y-axis log scale # SOLUTION START plt.plot(*zip(*points)) plt.yscale("log") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert len(ax.get_lines()) == 1 assert np.all(ax.get_lines()[0]._xy == np.array(points)) assert ax.get_yscale() == "log" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001986
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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)) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing import matplotlib 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 with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001987
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns sns.set_style("whitegrid") tips = sns.load_dataset("tips") ax = sns.boxplot(x="day", y="total_bill", data=tips) # set the y axis limit to be 0 to 40 # SOLUTION START plt.ylim(0, 40) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing # should have some shaded regions ax = plt.gca() yaxis = ax.get_yaxis() np.testing.assert_allclose(ax.get_ybound(), [0, 40]) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001988
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import matplotlib.pyplot as plt import numpy xlabels = list("ABCD") ylabels = list("CDEF") rand_mat = numpy.random.rand(4, 4) # Plot of heatmap with data in rand_mat and use xlabels for x-axis labels and ylabels as the y-axis labels # Make the x-axis tick labels appear on top of the heatmap and invert the order or the y-axis labels (C to F from top to bottom) # SOLUTION START plt.pcolor(rand_mat) plt.xticks(numpy.arange(0.5, len(xlabels)), xlabels) plt.yticks(numpy.arange(0.5, len(ylabels)), ylabels) ax = plt.gca() ax.invert_yaxis() ax.xaxis.tick_top() # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.get_ylim()[0] > ax.get_ylim()[1] assert ax.xaxis._major_tick_kw["tick2On"] assert ax.xaxis._major_tick_kw["label2On"] assert not ax.xaxis._major_tick_kw["tick1On"] assert not ax.xaxis._major_tick_kw["label1On"] assert len(ax.get_xticklabels()) == len(xlabels) assert len(ax.get_yticklabels()) == len(ylabels) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001989
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() assert tuple(f.get_size_inches()) == (8.0, 8.0) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001990
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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 label the x axis as "X" # Make both the x axis ticks and the axis label red # SOLUTION START fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x, y) ax.set_xlabel("X", c="red") ax.xaxis.label.set_color("red") ax.tick_params(axis="x", colors="red") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() plt.show() assert ax.xaxis.label._color in ["red", "r"] or ax.xaxis.label._color == ( 1.0, 0.0, 0.0, 1.0, ) assert ax.xaxis._major_tick_kw["color"] in ["red", "r"] or ax.xaxis._major_tick_kw[ "color" ] == (1.0, 0.0, 0.0, 1.0) assert ax.xaxis._major_tick_kw["labelcolor"] in ["red", "r"] or ax.xaxis._major_tick_kw[ "color" ] == (1.0, 0.0, 0.0, 1.0) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001991
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import numpy as np import matplotlib.pyplot as plt H = np.random.randn(10, 10) # show the 2d array H in black and white # SOLUTION START plt.imshow(H, cmap="gray") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing import matplotlib ax = plt.gca() assert len(ax.images) == 1 assert isinstance(ax.images[0].cmap, matplotlib.colors.LinearSegmentedColormap) assert ax.images[0].cmap.name == "gray" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001992
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import matplotlib import matplotlib.pyplot as plt import pandas as pd df = pd.DataFrame( { "celltype": ["foo", "bar", "qux", "woz"], "s1": [5, 9, 1, 7], "s2": [12, 90, 13, 87], } ) # For data in df, make a bar plot of s1 and s1 and use celltype as the xlabel # Make the x-axis tick labels rotate 45 degrees # SOLUTION START df = df[["celltype", "s1", "s2"]] df.set_index(["celltype"], inplace=True) df.plot(kind="bar", alpha=0.75, rot=45) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() plt.show() assert len(ax.patches) > 0 assert len(ax.xaxis.get_ticklabels()) > 0 for t in ax.xaxis.get_ticklabels(): assert t._rotation == 45 all_ticklabels = [t.get_text() for t in ax.xaxis.get_ticklabels()] for cell in ["foo", "bar", "qux", "woz"]: assert cell in all_ticklabels with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001993
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing import matplotlib 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) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001994
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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") # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing 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)) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001995
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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(1, 1) plt.xlim(1, 10) plt.xticks(range(1, 10)) ax.plot(y, x) # change the second x axis tick label to "second" but keep other labels in numerical # SOLUTION START a = ax.get_xticks().tolist() a[1] = "second" ax.set_xticklabels(a) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.xaxis.get_ticklabels()[1]._text == "second" assert ax.xaxis.get_ticklabels()[0]._text == "1" with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001996
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() import matplotlib.pyplot as plt fig, axes = plt.subplots(ncols=2, nrows=2, figsize=(8, 6)) axes = axes.flatten() for ax in axes: ax.set_ylabel(r"$\ln\left(\frac{x_a-x_b}{x_a-x_c}\right)$") ax.set_xlabel(r"$\ln\left(\frac{x_a-x_d}{x_a-x_e}\right)$") plt.show() plt.clf() # Copy the previous plot but adjust the subplot padding to have enough space to display axis labels # SOLUTION START fig, axes = plt.subplots(ncols=2, nrows=2, figsize=(8, 6)) axes = axes.flatten() for ax in axes: ax.set_ylabel(r"$\ln\left(\frac{x_a-x_b}{x_a-x_c}\right)$") ax.set_xlabel(r"$\ln\left(\frac{x_a-x_d}{x_a-x_e}\right)$") plt.tight_layout() # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing f = plt.gcf() assert tuple(f.get_size_inches()) == (8, 6) assert f.subplotpars.hspace > 0.2 assert f.subplotpars.wspace > 0.2 assert len(f.axes) == 4 for ax in f.axes: assert ( ax.xaxis.get_label().get_text() == "$\\ln\\left(\\frac{x_a-x_d}{x_a-x_e}\\right)$" ) assert ( ax.yaxis.get_label().get_text() == "$\\ln\\left(\\frac{x_a-x_b}{x_a-x_c}\\right)$" ) with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)
000001997
import pickle import argparse parser = argparse.ArgumentParser() parser.add_argument("--test_case", type=int, default=1) args = parser.parse_args() 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) # SOLUTION END plt.savefig('result/plot.png', bbox_inches ='tight') #Image Testing from PIL import Image import numpy as np code_img = np.array(Image.open('result/plot.png')) oracle_img = np.array(Image.open('ans/oracle_plot.png')) sample_image_stat = ( code_img.shape == oracle_img.shape and np.allclose(code_img, oracle_img) ) if sample_image_stat: with open('result/result_1.pkl', 'wb') as file: # if image test passed, we save True to the result file pickle.dump(True, file) # Testing ax = plt.gca() assert ax.xaxis._major_tick_kw["tick2On"] assert ax.xaxis._major_tick_kw["tick1On"] with open('result/result_1.pkl', 'wb') as file: # or if execution-based test passed, we save True to the result file pickle.dump(True, file)