Empty output file for simple polar plot
Hello guys, I tried to convert a Matlab polar plot to a tex.-file with matlab2tikz, but the output file is empty. My matlab code looks something like:
figure polarplot(dat.acc)%array with about 40 entries for the radius ax = gca; d = ax.ThetaDir; ax.ThetaZeroLocation = 'top'; rticklabels({'a = 0,0 m/s^2','a = 0,5 m/s^2','a = 1,0 m/s^2','a = 1,5 m/s^2'})
matlab2tikz('polar_plot_test.tex');
the output looks like this: % This file was created by matlab2tikz. % %The latest updates can be retrieved from % http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz %where you can also make suggestions and rate matlab2tikz. % \begin{tikzpicture} \end{tikzpicture}%
I also tried cleanfigure but with no result. I could not find anything about this issue by now. I really would appreciate some help.
Thanks and have a nice weekend, greets Carl
Cleanfigure will do you no good in this case.
The underlying problem is that polarplot creates a special kind of PolarAxes, which is not expected by matlab2tikz and hence not translated. There is a partial workaround: use polar (i.e. the old syntax) instead of polarplot: internally, that is a regular Axes object which is tweaked to such an extent that it looks like a polar plot.
Thanks egeerardyn for your quick response. Unfortunately I some errors using matlab2tikz on the plot generated with the old polar function. #####Code##### theta = 0:0.17:2*pi;
figure polar(theta,transpose(dat.acc)) ################ ######errors######## Error using view (line 91) One output argument is not supported. To query the current azimuth and elevation, request two output arguments.
Error in matlab2tikz>getRelativeAxesPosition (line 5042) projection = view(axesHandle);
Error in matlab2tikz>getAxesPosition (line 4987) relPos = getRelativeAxesPosition(m2t, handle, axesBoundingBox);
Error in matlab2tikz>retrievePositionOfAxes (line 975) pos = getAxesPosition(m2t, handle, m2t.cmdOpts.Results.width, ...
Error in matlab2tikz>drawAxes (line 831) m2t = retrievePositionOfAxes(m2t, handle);
Error in matlab2tikz>saveToFile (line 450) m2t = drawAxes(m2t, relevantAxesHandle);
Error in matlab2tikz (line 352) saveToFile(m2t, fid, fileWasOpen); ############
besides, the plot I generated with polar is not closed, there is a gap between the last and the first value.. this should not be, as the values for 0 and 360 are exactly the same.
I think this is going to far. Since the data file is very small (only 37 entries) I think it's easier to write the tikz-file my self.
Thanks for your help though! Carl
Hello,
have there been done any improvements so far concerning the topic?
Kind regards
Hi, thanks for asking. No, nothing new. I switched to python in the end. Thanks for your support! Carl
Ok, sad thing. Do you have a good adress to get informed about how to do it in python? Kind regards
It's been a while, but I give my best: The plot is made in python using the Matplotlib library (import matplotlib as plt). See doc here: https://matplotlib.org/). I was plotting directional sea spectra using pcolormesh in polar coordinates. But there are a lot of different ways to plot polar coordinates in matplotlib. I recommend using the image search of your preferred search engine to find the name of what you are looking for. For the example of a directional sea spectrum see:
- Polar plot (here using pcolormesh for directional wave spectra https://stackoverflow.com/questions/36113331/pcolormesh-in-polar-coordinates)
- Converting Matplotlib to LaTex: https://timodenk.com/blog/exporting-matplotlib-plots-to-latex/
Hope that helps! Carl
OK thank you very much :)
Hello,
I did it all in python now, but still I'll get an empty output 🗡️ ` import matplotlib.pyplot as plt import numpy as np import tikzplotlib
plt.style.use("ggplot")
t = np.arange(0.0, 2.0, 0.1) s = np.sin(2 * np.pi * t) s2 = np.cos(2 * np.pi * t) plt.plot(t, s, "o-", lw=4.1) plt.plot(t, s2, "o-", lw=4.1) plt.xlabel("time (s)") plt.ylabel("Voltage (mV)") plt.title("Simple plot $\frac{\alpha}{2}$") plt.grid(True) plt.show()
tikzplotlib.save("test.tex") `
What yould be the problem? Kind regards
Hi,
your title syntax is not quite correct. Try with plt.title(r'Simple plot $\frac{\alpha}{2}$')
Have a look here for explanation and reference: https://matplotlib.org/stable/tutorials/text/mathtext.html Best Carl