ltrujello / Tikz-Python

An object-oriented Python approach towards providing a giant wrapper for Tikz code, with the goal of streamlining the process of creating complex figures for TeX documents.
https://ltrujello.github.io/Tikz-Python
MIT License
21 stars 2 forks source link

[Feature Request (Maybe?)] Could Tikz-Python be extended to matplotlib backend? #5

Open Saltsmart opened 1 month ago

Saltsmart commented 1 month ago

I really love the object-oriented style of tikzpy ♥. Here is a further request to extend it to matplotlib (Maybe a similar package could be developed).

Matplotlib is designed to draw plots, not diagrams, but it implements many basic shapes, such as lines, rectangles, circles... It has some pros that Tikz doesn't:

It is not an easy task, of course. I created a question in StackOverflow (it's hidden because the bot thinks this question is seeking recommendations for software libraries 😂):

How can we use matplotlib to create diagrams like Tikz? Here is an official example: Matplotlib for Making Diagrams However, it produces a fixed-size canvas which wastes the space (By contrast, Tikz leaves no margin outside the items). I want to have an adjustable canvas to contain all drawn items without margins. Besides, the shapes in this diagram will be distorted after some operations like plt.tight_layout().

However, I believe we could do the handy things first, applying the existing api in Tikz-python to matplotlib. If you are interested, I feel very glad to participate.

ltrujello commented 3 weeks ago

I've also wondered if this is possible, as I personally really do not like TeX or LaTeX (although I have been forced to know a lot about them haha). I think this would require more knowledge about the matplotlib backend systems and how they generate the pngs. Since graphics (circles, squares, etc.) can be abstracted irrespective of the backend (which makes them suitable candidates for object oriented programming) this could be theoretically possible.

I think at minimum it would require investigating: How hard is it to draw basic objects like circles or lines in matplotlib? Do they look as nice in matplotlib? Is the coordinate system that matplotlib uses the same as the coordinate system of TikZ?

I once thought of doing this for PDFs (i.e. cut out of TeX middle man and just go straight to PDFs) and I studied how PDFs worked. I quickly found that PDFs are extremely complex beasts, and it's hard to get a PDF to look the same across different computers. But maybe it would be easier with PNGs.