|
8 | 8 | from nose.tools import raises
|
9 | 9 |
|
10 | 10 | import numpy as np
|
| 11 | +from scipy.spatial import Delaunay |
11 | 12 |
|
12 | 13 |
|
13 | 14 | class TestDistplot(TestCase):
|
@@ -529,3 +530,309 @@ def test_dendrogram_colorscale(self):
|
529 | 530 | self.assert_dict_equal(dendro['data'][0], expected_dendro['data'][0])
|
530 | 531 | self.assert_dict_equal(dendro['data'][1], expected_dendro['data'][1])
|
531 | 532 | self.assert_dict_equal(dendro['data'][2], expected_dendro['data'][2])
|
| 533 | + |
| 534 | + |
| 535 | +class TestTrisurf(NumpyTestUtilsMixin, TestCase): |
| 536 | + |
| 537 | + def test_vmin_and_vmax(self): |
| 538 | + |
| 539 | + # check if vmin is greater than or equal to vmax |
| 540 | + u = np.linspace(0, 2, 2) |
| 541 | + v = np.linspace(0, 2, 2) |
| 542 | + u, v = np.meshgrid(u, v) |
| 543 | + u = u.flatten() |
| 544 | + v = v.flatten() |
| 545 | + |
| 546 | + x = u |
| 547 | + y = v |
| 548 | + z = u*v |
| 549 | + |
| 550 | + points2D = np.vstack([u, v]).T |
| 551 | + tri = Delaunay(points2D) |
| 552 | + simplices = tri.simplices |
| 553 | + |
| 554 | + pattern = ( |
| 555 | + "Incorrect relation between vmin and vmax. The vmin value cannot " |
| 556 | + "be bigger than or equal to the value of vmax." |
| 557 | + ) |
| 558 | + |
| 559 | + self.assertRaisesRegexp(PlotlyError, pattern, |
| 560 | + tls.FigureFactory.create_trisurf, |
| 561 | + x, y, z, simplices) |
| 562 | + |
| 563 | + def test_valid_colormap(self): |
| 564 | + |
| 565 | + # create data for trisurf plot |
| 566 | + u = np.linspace(-np.pi, np.pi, 3) |
| 567 | + v = np.linspace(-np.pi, np.pi, 3) |
| 568 | + u, v = np.meshgrid(u, v) |
| 569 | + u = u.flatten() |
| 570 | + v = v.flatten() |
| 571 | + |
| 572 | + x = u |
| 573 | + y = u*np.cos(v) |
| 574 | + z = u*np.sin(v) |
| 575 | + |
| 576 | + points2D = np.vstack([u, v]).T |
| 577 | + tri = Delaunay(points2D) |
| 578 | + simplices = tri.simplices |
| 579 | + |
| 580 | + # check that a valid plotly colorscale name is entered |
| 581 | + self.assertRaises(PlotlyError, tls.FigureFactory.create_trisurf, |
| 582 | + x, y, z, simplices, colormap='foo') |
| 583 | + |
| 584 | + # check that colormap is a list, if not a string |
| 585 | + |
| 586 | + pattern1 = ( |
| 587 | + "If 'colormap' is a list, then its items must be tripets of the " |
| 588 | + "form a,b,c or 'rgbx,y,z' where a,b,c are between 0 and 1 " |
| 589 | + "inclusive and x,y,z are between 0 and 255 inclusive." |
| 590 | + ) |
| 591 | + |
| 592 | + self.assertRaisesRegexp(PlotlyError, pattern1, |
| 593 | + tls.FigureFactory.create_trisurf, |
| 594 | + x, y, z, simplices, colormap=3) |
| 595 | + |
| 596 | + # check: if colormap is a list of rgb color strings, make sure the |
| 597 | + # entries of each color are no greater than 255.0 |
| 598 | + |
| 599 | + pattern2 = ( |
| 600 | + "Whoops! The elements in your rgb colormap tuples " |
| 601 | + "cannot exceed 255.0." |
| 602 | + ) |
| 603 | + |
| 604 | + self.assertRaisesRegexp(PlotlyError, pattern2, |
| 605 | + tls.FigureFactory.create_trisurf, |
| 606 | + x, y, z, simplices, |
| 607 | + colormap=['rgb(1, 2, 3)', 'rgb(4, 5, 600)']) |
| 608 | + |
| 609 | + # check: if colormap is a list of tuple colors, make sure the entries |
| 610 | + # of each tuple are no greater than 1.0 |
| 611 | + |
| 612 | + pattern3 = ( |
| 613 | + "Whoops! The elements in your rgb colormap tuples " |
| 614 | + "cannot exceed 1.0." |
| 615 | + ) |
| 616 | + |
| 617 | + self.assertRaisesRegexp(PlotlyError, pattern3, |
| 618 | + tls.FigureFactory.create_trisurf, |
| 619 | + x, y, z, simplices, |
| 620 | + colormap=[(0.2, 0.4, 0.6), (0.8, 1.0, 1.2)]) |
| 621 | + |
| 622 | + def test_trisurf_all_args(self): |
| 623 | + |
| 624 | + # check if trisurf plot matches with expected output |
| 625 | + u = np.linspace(-np.pi, np.pi, 3) |
| 626 | + v = np.linspace(-np.pi, np.pi, 3) |
| 627 | + u, v = np.meshgrid(u, v) |
| 628 | + u = u.flatten() |
| 629 | + v = v.flatten() |
| 630 | + |
| 631 | + x = u |
| 632 | + y = u*np.cos(v) |
| 633 | + z = u*np.sin(v) |
| 634 | + |
| 635 | + points2D = np.vstack([u, v]).T |
| 636 | + tri = Delaunay(points2D) |
| 637 | + simplices = tri.simplices |
| 638 | + |
| 639 | + test_trisurf_plot = tls.FigureFactory.create_trisurf( |
| 640 | + x, y, z, simplices, colormap='Blues', |
| 641 | + title='Fun', |
| 642 | + showbackground=False, |
| 643 | + backgroundcolor='rgb(1, 20, 10)', |
| 644 | + gridcolor='rgb(0, 20, 50)', |
| 645 | + zerolinecolor='rgb(25, 255, 15)', |
| 646 | + height=500, width=500, |
| 647 | + aspectratio=dict(x=0.7, y=0.6, z=1.2) |
| 648 | + ) |
| 649 | + |
| 650 | + exp_trisurf_plot = { |
| 651 | + 'data': [{'facecolor': ['rgb(112.5, 115.00000000000001, 196.0)', |
| 652 | + 'rgb(220.0, 220.0, 220.0)', |
| 653 | + 'rgb(112.5, 115.00000000000001, 196.0)', |
| 654 | + 'rgb(5.0, 10.0, 172.0)', |
| 655 | + 'rgb(112.5, 115.00000000000001, 196.0)', |
| 656 | + 'rgb(5.0, 10.0, 172.0)', |
| 657 | + 'rgb(112.5, 115.00000000000001, 196.0)', |
| 658 | + 'rgb(220.0, 220.0, 220.0)'], |
| 659 | + 'i': [3, 1, 1, 5, 7, 3, 5, 7], |
| 660 | + 'j': [1, 3, 5, 1, 3, 7, 7, 5], |
| 661 | + 'k': [4, 0, 4, 2, 4, 6, 4, 8], |
| 662 | + 'name': '', |
| 663 | + 'type': 'mesh3d', |
| 664 | + 'x': np.array([-3.14159265, |
| 665 | + 0., |
| 666 | + 3.14159265, |
| 667 | + -3.14159265, |
| 668 | + 0., |
| 669 | + 3.14159265, |
| 670 | + -3.14159265, |
| 671 | + 0., |
| 672 | + 3.14159265]), |
| 673 | + 'y': np.array([3.14159265, |
| 674 | + -0., |
| 675 | + -3.14159265, |
| 676 | + -3.14159265, |
| 677 | + 0., |
| 678 | + 3.14159265, |
| 679 | + 3.14159265, |
| 680 | + -0., |
| 681 | + -3.14159265]), |
| 682 | + 'z': np.array([3.84734139e-16, |
| 683 | + -0.00000000e+00, |
| 684 | + -3.84734139e-16, |
| 685 | + -0.00000000e+00, |
| 686 | + 0.00000000e+00, |
| 687 | + 0.00000000e+00, |
| 688 | + -3.84734139e-16, |
| 689 | + 0.00000000e+00, |
| 690 | + 3.84734139e-16])}, |
| 691 | + {'line': {'color': 'rgb(50, 50, 50)', 'width': 1.5}, |
| 692 | + 'mode': 'lines', |
| 693 | + 'type': 'scatter3d', |
| 694 | + 'x': [-3.1415926535897931, |
| 695 | + 0.0, |
| 696 | + 0.0, |
| 697 | + -3.1415926535897931, |
| 698 | + None, |
| 699 | + 0.0, |
| 700 | + -3.1415926535897931, |
| 701 | + -3.1415926535897931, |
| 702 | + 0.0, |
| 703 | + None, |
| 704 | + 0.0, |
| 705 | + 3.1415926535897931, |
| 706 | + 0.0, |
| 707 | + 0.0, |
| 708 | + None, |
| 709 | + 3.1415926535897931, |
| 710 | + 0.0, |
| 711 | + 3.1415926535897931, |
| 712 | + 3.1415926535897931, |
| 713 | + None, |
| 714 | + 0.0, |
| 715 | + -3.1415926535897931, |
| 716 | + 0.0, |
| 717 | + 0.0, |
| 718 | + None, |
| 719 | + -3.1415926535897931, |
| 720 | + 0.0, |
| 721 | + -3.1415926535897931, |
| 722 | + -3.1415926535897931, |
| 723 | + None, |
| 724 | + 3.1415926535897931, |
| 725 | + 0.0, |
| 726 | + 0.0, |
| 727 | + 3.1415926535897931, |
| 728 | + None, |
| 729 | + 0.0, |
| 730 | + 3.1415926535897931, |
| 731 | + 3.1415926535897931, |
| 732 | + 0.0, |
| 733 | + None], |
| 734 | + 'y': [-3.1415926535897931, |
| 735 | + -0.0, |
| 736 | + 0.0, |
| 737 | + -3.1415926535897931, |
| 738 | + None, |
| 739 | + -0.0, |
| 740 | + -3.1415926535897931, |
| 741 | + 3.1415926535897931, |
| 742 | + -0.0, |
| 743 | + None, |
| 744 | + -0.0, |
| 745 | + 3.1415926535897931, |
| 746 | + 0.0, |
| 747 | + -0.0, |
| 748 | + None, |
| 749 | + 3.1415926535897931, |
| 750 | + -0.0, |
| 751 | + -3.1415926535897931, |
| 752 | + 3.1415926535897931, |
| 753 | + None, |
| 754 | + -0.0, |
| 755 | + -3.1415926535897931, |
| 756 | + 0.0, |
| 757 | + -0.0, |
| 758 | + None, |
| 759 | + -3.1415926535897931, |
| 760 | + -0.0, |
| 761 | + 3.1415926535897931, |
| 762 | + -3.1415926535897931, |
| 763 | + None, |
| 764 | + 3.1415926535897931, |
| 765 | + -0.0, |
| 766 | + 0.0, |
| 767 | + 3.1415926535897931, |
| 768 | + None, |
| 769 | + -0.0, |
| 770 | + 3.1415926535897931, |
| 771 | + -3.1415926535897931, |
| 772 | + -0.0, |
| 773 | + None], |
| 774 | + 'z': [-0.0, |
| 775 | + -0.0, |
| 776 | + 0.0, |
| 777 | + -0.0, |
| 778 | + None, |
| 779 | + -0.0, |
| 780 | + -0.0, |
| 781 | + 3.8473413874435795e-16, |
| 782 | + -0.0, |
| 783 | + None, |
| 784 | + -0.0, |
| 785 | + 0.0, |
| 786 | + 0.0, |
| 787 | + -0.0, |
| 788 | + None, |
| 789 | + 0.0, |
| 790 | + -0.0, |
| 791 | + -3.8473413874435795e-16, |
| 792 | + 0.0, |
| 793 | + None, |
| 794 | + 0.0, |
| 795 | + -0.0, |
| 796 | + 0.0, |
| 797 | + 0.0, |
| 798 | + None, |
| 799 | + -0.0, |
| 800 | + 0.0, |
| 801 | + -3.8473413874435795e-16, |
| 802 | + -0.0, |
| 803 | + None, |
| 804 | + 0.0, |
| 805 | + 0.0, |
| 806 | + 0.0, |
| 807 | + 0.0, |
| 808 | + None, |
| 809 | + 0.0, |
| 810 | + 0.0, |
| 811 | + 3.8473413874435795e-16, |
| 812 | + 0.0, |
| 813 | + None]}], |
| 814 | + 'layout': {'height': 500, |
| 815 | + 'scene': {'aspectratio': {'x': 0.7, 'y': 0.6, 'z': 1.2}, |
| 816 | + 'xaxis': {'backgroundcolor': 'rgb(1, 20, 10)', |
| 817 | + 'gridcolor': 'rgb(0, 20, 50)', |
| 818 | + 'showbackground': False, |
| 819 | + 'zerolinecolor': 'rgb(25, 255, 15)'}, |
| 820 | + 'yaxis': {'backgroundcolor': 'rgb(1, 20, 10)', |
| 821 | + 'gridcolor': 'rgb(0, 20, 50)', |
| 822 | + 'showbackground': False, |
| 823 | + 'zerolinecolor': 'rgb(25, 255, 15)'}, |
| 824 | + 'zaxis': {'backgroundcolor': 'rgb(1, 20, 10)', |
| 825 | + 'gridcolor': 'rgb(0, 20, 50)', |
| 826 | + 'showbackground': False, |
| 827 | + 'zerolinecolor': 'rgb(25, 255, 15)'}}, |
| 828 | + 'title': 'Fun', |
| 829 | + 'width': 500}} |
| 830 | + |
| 831 | + self.assert_dict_equal(test_trisurf_plot['data'][0], |
| 832 | + exp_trisurf_plot['data'][0]) |
| 833 | + |
| 834 | + self.assert_dict_equal(test_trisurf_plot['data'][1], |
| 835 | + exp_trisurf_plot['data'][1]) |
| 836 | + |
| 837 | + self.assert_dict_equal(test_trisurf_plot['layout'], |
| 838 | + exp_trisurf_plot['layout']) |
0 commit comments