Dash alignment similar to Illustrator

Hello,

I was wondering if it was possible to do dash alignment similar to how Adobe Illustrator allows you to have corner-aligned dashed, which for closed shapes will make sure the dash is even about the corner, and for lines it makes the line dashes symmetric. Ideally you would be able to set the dash pattern alignment such that it is independent of scaling and the number of dashes.

The minimum example I have is:

fig, axes = plt.subplots(1,2)
for ax in axes:
    ax.vlines([0.25, 0.75], 0.25, 0.75, linestyle='--')
    ax.hlines([0.25, 0.75], 0.25, 0.75, linestyle='--')
    
axes[0].set_ylim(0, 1)
axes[0].set_xlim(0, 1)

dash_alignment

If I don’t change the x/ylim then the dash pattern changes, which is clear from where it meets with other lines. This can make fine touches on a figure tedious.

I am currently using matplotlib version 3.3.4 but plan to upgrade soon.

There is no such algorithm in Matplotlib that I know of. See matplotlib.lines.Line2D — Matplotlib 3.4.1 documentation for what there is. But if you want to paint dashes so precisely, I suspect you’d have to draw the individual lines yourself.