mplcyberpunk icon indicating copy to clipboard operation
mplcyberpunk copied to clipboard

Found an error in when dealing with step plots

Open AlvaroNovillo opened this issue 1 year ago • 0 comments

Hi! Your current module does only support step plots with the variable where = ''pre" (which is the default value, as indicated in the documentation. I've changed the code so that the user can input the parameter themselves in order to fix it, but this is not the optimal solution. Could you fix that in the next version?

def make_lines_glow(ax=None, n_glow_lines=10, diff_linewidth=1.05, alpha_line=0.3, where=None): """Add a glow effect to the lines in an axis object.

            Each existing line is redrawn several times with increasing width and low alpha to create the glow effect.
            """
            if not ax:
                ax = plt.gca()
        
            lines = ax.get_lines()
        
            alpha_value = alpha_line / n_glow_lines
        
            for line in lines:
                data = line.get_data()
                linewidth = line.get_linewidth()
                
                try:
                    step_type = line.get_drawstyle().split('-')[1]
                except:
                    step_type = None
        
                for n in range(1, n_glow_lines + 1):
                    if step_type:
                        # Use the 'where' parameter if it's provided
                        if where is not None:
                            glow_line, = ax.step(*data, where=where)
                        else:
                            glow_line, = ax.step(*data)
                    else:
                        glow_line, = ax.plot(*data)
                    glow_line.update_from(line)
        
                    glow_line.set_alpha(alpha_value)
                    glow_line.set_linewidth(linewidth + (diff_linewidth * n))
                    glow_line.is_glow_line = True

`

AlvaroNovillo avatar Feb 14 '24 10:02 AlvaroNovillo