@@ -1365,6 +1365,116 @@ def test_gantt_all_args(self):
1365
1365
self .assertEqual (test_gantt_chart ['layout' ],
1366
1366
exp_gantt_chart ['layout' ])
1367
1367
1368
+
1369
+ class Test2D_Density (TestCase ):
1370
+
1371
+ def test_validate_2D_density (self ):
1372
+
1373
+ # validate that x and y contain only numbers
1374
+
1375
+ x = [1 , 2 ]
1376
+
1377
+ y = ['a' , 2 ]
1378
+
1379
+ pattern = ("All elements of your 'x' and 'y' lists must be numbers." )
1380
+
1381
+ self .assertRaisesRegexp (PlotlyError , pattern ,
1382
+ tls .FigureFactory .create_2D_density , x , y )
1383
+
1384
+ # validate that x and y are the same length
1385
+
1386
+ x2 = [1 ]
1387
+
1388
+ y2 = [1 , 2 ]
1389
+
1390
+ pattern2 = ("Both lists 'x' and 'y' must be the same length." )
1391
+
1392
+ self .assertRaisesRegexp (PlotlyError , pattern2 ,
1393
+ tls .FigureFactory .create_2D_density , x2 , y2 )
1394
+
1395
+ def test_2D_density_all_args (self ):
1396
+
1397
+ # check if 2D_density data matches with expected output
1398
+
1399
+ x = [1 , 2 ]
1400
+ y = [2 , 4 ]
1401
+
1402
+ colorscale = ['#7A4579' , '#D56073' , 'rgb(236,158,105)' ,
1403
+ (1 , 1 , 0.2 ), (0.98 , 0.98 , 0.98 )]
1404
+
1405
+ test_2D_density_chart = tls .FigureFactory .create_2D_density (
1406
+ x , y , colorscale = colorscale , hist_color = 'rgb(255, 237, 222)' ,
1407
+ point_size = 3 , height = 800 , width = 800 )
1408
+
1409
+ exp_2D_density_chart = {
1410
+ 'data' : [{'marker' : {'color' : 'rgb(0.0, 0.0, 127.5)' ,
1411
+ 'opacity' : 0.4 ,
1412
+ 'size' : 3 },
1413
+ 'mode' : 'markers' ,
1414
+ 'name' : 'points' ,
1415
+ 'type' : 'scatter' ,
1416
+ 'x' : [1 , 2 ],
1417
+ 'y' : [2 , 4 ]},
1418
+ {'colorscale' : [[0.0 , 'rgb(122.0, 69.0, 121.0)' ],
1419
+ [0.25 , 'rgb(213.0, 96.0, 115.0)' ],
1420
+ [0.5 , 'rgb(236.0, 158.0, 105.0)' ],
1421
+ [0.75 , 'rgb(255.0, 255.0, 51.0)' ],
1422
+ [1.0 , 'rgb(249.9, 249.9, 249.9)' ]],
1423
+ 'name' : 'density' ,
1424
+ 'ncontours' : 20 ,
1425
+ 'reversescale' : True ,
1426
+ 'showscale' : False ,
1427
+ 'type' : 'histogram2dcontour' ,
1428
+ 'x' : [1 , 2 ],
1429
+ 'y' : [2 , 4 ]},
1430
+ {'marker' : {'color' : 'rgb(255.0, 237.0, 222.0)' },
1431
+ 'name' : 'x density' ,
1432
+ 'type' : 'histogram' ,
1433
+ 'x' : [1 , 2 ],
1434
+ 'yaxis' : 'y2' },
1435
+ {'marker' : {'color' : 'rgb(255.0, 237.0, 222.0)' },
1436
+ 'name' : 'y density' ,
1437
+ 'type' : 'histogram' ,
1438
+ 'xaxis' : 'x2' ,
1439
+ 'y' : [2 , 4 ]}],
1440
+ 'layout' : {'autosize' : False ,
1441
+ 'bargap' : 0 ,
1442
+ 'height' : 800 ,
1443
+ 'hovermode' : 'closest' ,
1444
+ 'margin' : {'t' : 50 },
1445
+ 'showlegend' : False ,
1446
+ 'title' : 'Love' ,
1447
+ 'width' : 800 ,
1448
+ 'xaxis' : {'___domain' : [0 , 0.85 ],
1449
+ 'showgrid' : False ,
1450
+ 'zeroline' : False },
1451
+ 'xaxis2' : {'___domain' : [0.85 , 1 ],
1452
+ 'showgrid' : False ,
1453
+ 'zeroline' : False },
1454
+ 'yaxis' : {'___domain' : [0 , 0.85 ],
1455
+ 'showgrid' : False ,
1456
+ 'zeroline' : False },
1457
+ 'yaxis2' : {'___domain' : [0.85 , 1 ],
1458
+ 'showgrid' : False ,
1459
+ 'zeroline' : False }}
1460
+ }
1461
+
1462
+ self .assertEqual (test_2D_density_chart ['data' ][0 ],
1463
+ exp_2D_density_chart ['data' ][0 ])
1464
+
1465
+ self .assertEqual (test_2D_density_chart ['data' ][1 ],
1466
+ exp_2D_density_chart ['data' ][1 ])
1467
+
1468
+ self .assertEqual (test_2D_density_chart ['data' ][2 ],
1469
+ exp_2D_density_chart ['data' ][2 ])
1470
+
1471
+ self .assertEqual (test_2D_density_chart ['data' ][3 ],
1472
+ exp_2D_density_chart ['data' ][3 ])
1473
+
1474
+ self .assertEqual (test_2D_density_chart ['layout' ],
1475
+ exp_2D_density_chart ['layout' ])
1476
+
1477
+
1368
1478
# class TestDistplot(TestCase):
1369
1479
1370
1480
# def test_scipy_import_error(self):
0 commit comments