简体   繁体   English

Matplotlib savefig与eps不会在3d图上的投影平面上绘制网格线

[英]Matplotlib savefig with eps doesn't draw grid lines in a projection plane on a 3d plot

In Matplotlib, I want to draw grid lines in all projection planes on a 3d plot in a EPS file. 在Matplotlib中,我想在EPS文件中的3d图上的所有投影平面上绘制网格线。
I wrote the below code. 我写了下面的代码。 The code works as desired on the figure window and the PNG file, but not on the EPS file. 该代码可在图形窗口和PNG文件上按预期工作,而在EPS文件上则无法工作。
In the EPS file, grid lines aren't drawn into one of three projection planes. 在EPS文件中,网格线未绘制到三个投影平面之一中。 I pasted the created PNG file (top) and EPS file (down, I can't paste .eps in this page. Hence, I pasted the converted image. I uploaded the EPS file to here (openload) .). 我粘贴了创建的PNG文件(顶部)和EPS文件(向下,我不能在该页面粘贴.eps。因此,我粘贴了转换后的图像。我将EPS文件上传到了这里(openload) 。)。
Is there any ways to fix this? 有什么办法可以解决这个问题?

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig1 = plt.figure()
ax1 = fig1.gca(projection='3d')
ax1.set_aspect("equal")
ax1.view_init(elev=30., azim=40)

fileid="test"
path="C:..."
fig1.savefig(path+fileid+".eps", dpi=300)
fig1.savefig(path+fileid+".png", dpi=300)

PNG文件 EPS文件

Well the EPS does draw the grid line. 好了,EPS 确实画出了网格线。 The problem is that it draws them the same colour as the flat fill for the plane. 问题在于它绘制的颜色与平面的平面填充相同。

If you open the EPS file with a text editor, and go to line 261 you will see: 如果使用文本编辑器打开EPS文件,然后转到第261行,您将看到:

0.900 setgray
gsave
288.863762 206.238981 m
165.545964 132.223634 l
158.321608 301.489923 l
288.311228 367.946472 l
gsave
fill

If you change the 0.900 setgray to 0.25 setgray then render the EPS you will see that the plane is drawn in a much darker shade of gray, and the grid lines are now easily visible. 如果将0.900 setgray更改为0.25 setgray然后渲染EPS,您将看到以较深的灰色阴影绘制了平面,现在可以轻松看到网格线。

I have no idea if that's something you can change in matplotlib, but that's where the gray values are being generated, there's nothing wrong with the EPS. 我不知道是否可以在matplotlib中进行更改,但这就是生成灰度值的地方,EPS没错。 From the PNG you created directly, it 'looks like' the gray values being selected for the planes are too dark and that's where your problem lies. 从您直接创建的PNG中,“看起来”为飞机选择的灰度值太暗,这就是问题所在。

As an experiment I tried changing the 3 gray values used to draw the planes from 0.950, 0.900 and 0.925 to 0.975, 0.945 and 0.960 and the results looked closer to the image you posted. 作为实验,我尝试将用于绘制平面的3个灰度值从0.950、0.900和0.925更改为0.975、0.945和0.960,结果看起来更接近于您发布的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM