Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(wyh):add plot test code #370

Merged
merged 6 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions ding/utils/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import pytest

from ding.utils.plot_helper import plot
from PIL import Image
import matplotlib.pyplot as plt
import seaborn as sns
from hbutils.testing import isolated_directory


@pytest.mark.unittest
Expand Down Expand Up @@ -31,5 +35,33 @@ def test_plot():
data2['label'] = 'line2'

data = [data1, data2]
plot(data, 'step', 'reward_rate', 'test_pic', './pic.jpg')
assert os.path.exists('./pic.jpg')
with isolated_directory():
plt.figure(1)
plot(data, 'step', 'reward_rate', 'test_pic', './pic.jpg')
assert os.path.exists('./pic.jpg')
plt.figure(2)
sns.set(style="darkgrid", font_scale=1.5)
sns.lineplot(x=np.concatenate((episode1, episode2)), y=np.concatenate((rewards1, rewards2)), label='line1')
sns.lineplot(x=np.concatenate((episode3, episode4)), y=np.concatenate((rewards3, rewards4)), label='line2')
plt.xlabel('step')
plt.ylabel('reward_rate')
plt.title('test_pic')
plt.savefig('./pic_compare.jpg')
I1 = Image.open('./pic.jpg')
I2 = Image.open('./pic_compare.jpg')
I1_array = np.array(I1)
I2_array = np.array(I2)
assert (I1_array - I2_array).mean() == 0
plt.figure(3)
sns.set(style="darkgrid", font_scale=1.5)
sns.lineplot(x=np.concatenate((episode1, episode2)), y=np.concatenate((rewards1, rewards2)), label='line1')
sns.lineplot(x=np.concatenate((episode3, episode4)), y=np.concatenate((rewards1, rewards3)), label='line2')
plt.xlabel('step')
plt.ylabel('reward_rate')
plt.title('test_pic')
plt.savefig('./pic_compare_diffpic.jpg')
I1 = Image.open('./pic.jpg')
I2 = Image.open('./pic_compare_diffpic.jpg')
I1_array = np.array(I1)
I2_array = np.array(I2)
assert (I1_array - I2_array).mean() < 100
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
'DI-toolkit>=0.0.2',
'hbutils>=0.5.0',
'moviepy',
'hbutils',
],
extras_require={
'test': [
Expand Down