0

I know that my question sounds desperate and also it is not a short reproducible example. However I am writing my thesis and I tried a test print. I couldnt print the document, written in TeX and viewed in pdf, because of one plot that is based on python (all other ones are created in R). I would be so gratefull to someone how could have a quick look at it. I'm really desperate right now because I don't want to take this graphic out of my work. I am not really familiar with python as I am using R, but just wanted to generate this plot for my thesis.

the Code.

I am referring to the figure in the section "Lasso coordinate descent Vary parameter l (lamda) for different results" (field [20]).

I am trying to save it as follows:

    %matplotlib inline
fig = plt.figure(figsize = (16,8))

#Surface plot
ax = fig.add_subplot(1, 2, 1, projection='3d')
ax.plot_surface(T1, T2, Z, rstride = 5, cstride = 5, cmap = 'jet', alpha=0.5)
ax.plot(theta_0,theta_1,J_history_lasso, marker = '*', color = 'r', alpha = .4, label = 'Gradient descent')

ax.set_xlabel('theta 1')
ax.set_ylabel('theta 2')
ax.set_zlabel('error')
ax.set_title('RSS gradient descent: Root at {}'.format(theta_result_lasso.ravel()))
ax.view_init(25, -40)


#Contour plot
ax = fig.add_subplot(1, 2, 2)
ax.contour(T1, T2, Z, 100, cmap = 'jet')
ax.quiver(theta_0[:-1], theta_1[:-1], anglesx, anglesy, scale_units = 'xy', angles = 'xy', scale = 1, color = 'r', alpha = .9)



 ax.set_xlabel(r'$\beta_1$', fontsize=20, labelpad = 10)
 ax.set_ylabel(r'$\beta_2$', fontsize=20, labelpad = 10)
 ax.set_zlabel(r'$\mathcal{L}(\beta)$', fontsize=20, labelpad = 10)
 ax.tick_params(labelsize=16)
 ax.set_title(r'Globales Minimum $\hat \beta$ = [{:0.0f}, {:0.2f}]'.format(roundi[0],roundi[1]), fontsize=20, pad=40)

 plt.show()

 fig.savefig("l18.pdf", bbox_inches='tight')

but I cant print out the regarding pdf. I also tried different types of printers. So it should be problem with the regarding figure.

12
  • It is an exception that it contradicts the usual format of this Forum. Commented Aug 23, 2018 at 19:36
  • 1
    just comment the line plt.show() Commented Aug 23, 2018 at 19:43
  • I'll try give me a second Commented Aug 23, 2018 at 19:43
  • Have you tried saving the figure as a png, and then linking it to the tex document? Commented Aug 23, 2018 at 19:45
  • 1
    Of course. I have already tried this. In your latex compiler, you will have to choose the option of ps--> pdf during compilation. Just google for more on your TeX editor...whichever you are using Commented Aug 23, 2018 at 20:08

2 Answers 2

1

Try saving it as .eps and use eps2pdf convertor to convert to pdf. Or just use .eps files in your LaTeX thesis. eps are vector plots and have really good resolutions.

Sign up to request clarification or add additional context in comments.

Comments

0

plt.show() shows the picture and clears the canvas. Your PDF file is empty. That's why you cannot print it. Either remove plt.show() or move it after the savefig.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.