79085192

Date: 2024-10-14 07:54:31
Score: 0.5
Natty:
Report link

This isn't the cleanest solution one could imagine, but you can set the widths to be in terms of the limits on the x-axis so that they "automatically" undo any scaling. This approach requires that you explicitly set the x-limits before you make the plot (since the width requires the values in advance) and that you not change/update the x-limits after the plot has been made.

ax.set_xlim(0, 101)
ax.boxplot(
    data,
    positions=x_positions,
    widths=0.1 * (ax.get_xlim()[1] - ax.get_xlim()[0]),
)

with xlimits 0 and 101

ax.set_xlim(0, 11)
ax.boxplot(...)

with xlimits 0 and 11

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Alex Duchnowski