tikzplotlib icon indicating copy to clipboard operation
tikzplotlib copied to clipboard

Use containers to improve translation of errorbar plot and bar charts

Open Naikless opened this issue 2 years ago • 0 comments

As suggested years ago here, I finally got around to implement some code that adds support for translating the container objects used by matplotlib for errorbars and bar charts to create pgfplots with the corresponding error bars and ybar/xbar styles.

The new functionality and the resulting tex output can be tested via the createBarPlots.py script.

Key advantages:

  • error bar plots and bar charts are plotted as a single \addplot command, greatly improving readability of the tex file and the possibility of later fine-tuning from latex.
  • repeated legend entries for every error bar feature as shown in https://github.com/texworld/tikzplotlib/issues/218 are avoided. Although legend representation in the resulting tex is not 1:1 as what is shown in matplotlib, I would consider it better than before. This should at least fix https://github.com/texworld/tikzplotlib/issues/453 and all related issues.

Although I tried to touch as little as possible of the existing code base, I realize that this is quite an intrusive PR, so don't hesitate to suggest any improvements or alterations that should be made. https://github.com/texworld/tikzplotlib/commit/d8182d5ee07d15065c9afa2953be2a73db624080 is optional, as it integrates the required changes into the original draw_line2d and _table instead of defining (mostly redundant) alternatives to be used with the containers.

Tests would of course need to be adjusted, that's why I would consider this WIP for the moment until you could have a first look.

Naikless avatar Apr 14 '22 14:04 Naikless