TeX - LaTeX Asked by Gene Cheypesh on August 4, 2021
I am trying to make a 2D density plot in python using tikzplotlib. I need to have the colorbar (and corresponding z-axis) in the log scale.
Here is the example of the figure in png that I want to have in tex format:
Here is the code I am using in python:
f = figure(figsize=(16.2,12.6))
ax = f.add_axes([0.2, 0.02, 0.72, 0.79])
axcolor = f.add_axes([0.95, 0.05, 0.02, 0.72])
im = ax.matshow(fun(X, Y), norm=LogNorm(vmin=1e-1, vmax=1e2))
t = [1e-2, 1e-1, 1e0, 1e1, 1e2]
f.colorbar(im, cax=axcolor, ticks=t)
tikzplotlib.save("2D.tex")
The problem is that the data is too big and tikzplotlib saves it as a separate png file which is then uploaded in 2D.tex. But then it is not in the log scale anymore.
I have done a great amount of research but all the answers I have found are dealing with cases when the density plot is defined by a matrix or function. I, instead, have a huge np.array.
I will be grateful for any help
This seems to be a bug in tikzplotlib and propably cannot be solved completely without a deeper understanding of the module. In general, as convenient as it is, I advise against using it away from simple line plots. The reason is that tikzplot is prone to errors and in most cases needs manual adjustments in the generated code. Another reason is to have consistent graphs with a consistent scheme, which should be better set with "pure" LaTex/PGFPlots. This is best achieved with "styles/templates" defined in PGFPlots.
To answer your question: a possible workaround would be to export the data and compile the document with LuaLatex. LuaLatex has no size limit and I highly recommend it, because it has many other advantages over pdfLaTex. If you want to create your whole document and not just the graph, you will probably have to make some adjustments to your document.
See What packages should I load with LuaTex? for more information.
I hope that this answer will help you a little.
Correct answer by Sunsheep on August 4, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP