I calculate with my own written "tree-framework" coordinates for tree-visulize/drawing (therefore I calculate coordinates for the nodes and the connections). I work under python 3.9 and I use for the drawing of the tree the matplotlib (version 3.3.3) and store the "result" with the matplotlib in an file on this way:
ptr_fig.set_canvas(matplotlib.backends.backend_agg.FigureCanvasAgg(ptr_fig))
ptr_fig.savefig(temporary_image_file_path, dpi = 100, format = "png")
All this work in general fine and perfect (here an few examples, I have implemented in my framework different tree-drawing-styles):
But at huge trees I can have this:
AND THAT IS AN THING WHAT I AT THE MOMENT NOT UNDERSTAND! WHAT GO HERE WRONG? I think it is any wrong setting at the matplotlib, but I don't know what
REMARK: The picture above is in reallity really huge with resolution 56200 * 5200
Another big picture viewed in MS-Edge (therefore picture included in html):
In the following an few background information's how I work in PRINCIPLE (the details in the reality are, of course, much more complex ==> I describe only that what is need and simplyfy things, but in principle is all what I write of course true)
With my tree-framework I calculate, for the to visual tree, the coordinates for all the nodes and the connections
- E.g. min calculated x-coordinate is 0 (e.g. for left side of the most left node in the tree)
- E.g. max calculated x-coordinate is 100 (e.g. for the right side of the most right node in the tree)
With the max calculated x- and y-coordinate I calculate the figsize (therefore, when the tree is more big so have the figure more inches)
DPI = 100
FACTOR = 10
x_pixels = FACTOR * max_x_tree_coord
y_pixels = FACTOR * max_y_tree_coord
ptr_fig = matplotlib.figure.Figure(figsize = (x_pixels / DPI, y_pixels / DPI),
dpi = DPI)
self.__ptr_axis = ptr_fig.gca()
Before I draw the tree with the matplotlib I "normalize" the cordinates which my tree-framework have calculated so that the x- and y-coord-values, which the matplotlib-framework receive are ONLY between 0 and 1 (therefore e.g. the variables "left" and "bottom" at the code down can have only values between 0 and 1)
Then I draw the nodes and connections, in the following the example how I draw the "box" of an node
p = plt.Rectangle((left, bottom),
width,
height,
fill = fill,
edgecolor = edgecolor,
facecolor = facecolor,
linewidth = linewidth)
p.set_transform(self.__ptr_axis.transAxes)
p.set_clip_on(False)
self.__ptr_axis.add_patch(p)
At the end I do
ptr_fig.set_canvas(matplotlib.backends.backend_agg.FigureCanvasAgg(ptr_fig))
ptr_fig.savefig(r"C:\path\to\my\tree_image.png", dpi = 100, format = "png")
I would be very happy when anybody have an idea what go wrong :-)
Already now many thanks for the answers
Best regards Fonso