sewkokot / opsvis

OpenSeesPy postprocessing and plotting module
GNU General Public License v3.0
35 stars 21 forks source link

Added `material_color` to prevent IndexError. #55

Open ajayakhatri opened 3 months ago

ajayakhatri commented 3 months ago

material_color dictionary was added to map material tags to their corresponding colors, and matcolor[matTag-1] was replaced with material_color[matTag] to prevent the error. Additionally, the default color of black was added with a feedback message.

The existing code uses matcolor[matTag-1] to assign color but there will be an IndexError if matTag is greater than the length of matcolor.

For example, in the snippet below matTag is 101 which is greater than the length of matcolor. matcolor[100] will result in list index out of range error.

            fib_sec_1 = [['section', 'Fiber', 1, '-GJ', 1.0e6],
                         ['patch', 'quad', 101, 4, 1,  0.032, 0.317, -0.311, 0.067, -0.266, 0.005, 0.077, 0.254],  # noqa: E501
                         ['patch', 'quad', 1, 1, 4,  -0.075, 0.144, -0.114, 0.116, 0.075, -0.144, 0.114, -0.116],  # noqa: E501
                         ['patch', 'quad', 30, 4, 1,  0.266, -0.005,  -0.077, -0.254,  -0.032, -0.317,  0.311, -0.067]  # noqa: E501
                         ]
            opsv.fib_sec_list_to_cmds(fib_sec_1)
            matcolor = ['r', 'gold','b']   
            opsv.plot_fiber_section(fib_sec_1, matcolor=matcolor)