下面的代码将用带有^{id1}的svg标记编写svg文件$
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
x = np.random.standard_normal(10000)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(10000)
plt.hexbin(x,y, cmap=plt.cm.YlOrRd_r,gid="element")
plt.savefig("img.svg")
但是,如果我将rasterized=True标志添加到hexbin(),则gid在光栅化过程后丢失,并且图像.svg<;image tag包含一些随机标记id(如<;image^{id2})$
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
x = np.random.standard_normal(10000)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(10000)
plt.hexbin(x,y, cmap=plt.cm.YlOrRd_r,gid="element",rasterized=True)
plt.savefig("img.svg")
是否可以在输出图像标签中保留hexbin gid? 谢谢
更新需要解决的小问题
def saveFile(self,filename):
"""
save svg with updated image tag id's
"""
data = StringIO()
self.fig.savefig(data,format='svg',transparent=True)
data.seek(0)
img = minidom.parse(data)
it=0
for i in img.getElementsByTagName('image'):
i.setAttribute('id','img_'+self.gids[it])
it+=1
fw = open(filename,"w")
img.writexml(fw)
fw.close()
data.close()
img.unlink()
目前没有回答
相关问题 更多 >
编程相关推荐