相关疑难解决方法(0)

如何将pandas DataFrame表保存为png

我构建了一个结果的熊猫数据框.此数据框充当表.有MultiIndexed列,每行代表一个名称,即index=['name1','name2',...]创建DataFrame时.我想显示这个表并将其保存为png(或任何图形格式).目前,我能得到的最接近的是将其转换为html,但我想要一个png.看起来有类似的问题,如如何将Pandas数据帧/系列数据保存为数字?

但是,标记的解决方案将数据帧转换为线图(而不是表格),而另一个解决方案依赖于PySide,我只想因为无法将其安装在Linux上而远离它.我希望这段代码易于移植.我真的希望使用python可以轻松创建表格.所有帮助表示赞赏.

python pandas

42
推荐指数
8
解决办法
6万
查看次数

在Python中将HTML转换为图像

我想在Python中将以下HTML转换为PNG图像.

<html>
    <b>Bold text</b>
</html>
Run Code Online (Sandbox Code Playgroud)

当然,这个HTML就是一个例子.

我尝试了'pisa',但它将html转换为PDF,而不是图像.我可以将HTML转换为PDF然后将PDF转换为PNG,但我想知道是否有任何直接解决方案(即HTML到PNG).任何内置或外置模块都可以很好地工作.

如果这可以在Graphicsmagick或Imagemagick中完成,那么它将是完美的.

html python image imagemagick graphicsmagick

19
推荐指数
2
解决办法
6万
查看次数

如何从字符串生成带有selenium/phantomjs的png文件?

我正在使用selenium/phantomjs在python中创建html的png文件.有没有办法从html字符串或文件句柄(而不是网站)生成png?我搜索了selenium文档并用谷歌搜索但找不到答案.我有:

htmlString = '<html><body><div style="background-color:red;height:500px;width:500px;">This is a png</div></body></html>'
myFile = 'tmp.html'
f = open(myFile,'w')
f.write(htmlString) 

from selenium import webdriver  

driver = webdriver.PhantomJS()
driver.set_window_size(1024, 768) 
#driver.get('https://google.com/') # this works fine
driver.get(myFile) # passing the file name or htmlString doesn't work...creates a blank png with nothing
driver.save_screenshot('screen.png') 
driver.quit()

print "png file created"
Run Code Online (Sandbox Code Playgroud)

python selenium phantomjs

6
推荐指数
1
解决办法
2万
查看次数

Python:从matplotlib热图及其图例中保留Numpy NaN值

我有一个numpy数组,我需要绘制为热图.numpy数组还包含我需要从绘图中排除的NaN值.我在其他帖子中被告知numpy会自动掩盖情节中的NaN值,但它不知何故对我不起作用.这是一个示例代码

column_labels = list('ABCDEFGH')
row_labels = list('WXYZ')
fig, ax = plt.subplots()
data = np.array([[ 0.96753494,  0.52349944,  0.0254628 ,  0.5104103 ],
         [ 0.07320069,  0.91278731,  0.97094436,  0.70533351],
         [ 0.30162006,  0.49068337,  0.41837729,  0.71139215],
         [ 0.19786101,  0.15882713,  0.59028841,  0.06242765],
         [ 0.51505872,  0.07798389,  0.58790067,  0.44782683],
         [ 0.68975694,  0.53535385,  0.15696023,  0.35641951],
         [ 0.66481995,  0.03576846,  0.9623601 ,  0.96006395],
         [ 0.45865404,  0.50433582,  0.18182575,  0.35126449],])

data[3,:] = np.nan
heatmap = ax.pcolor(data, cmap=plt.cm.seismic)

fig.colorbar(heatmap)
# put the major ticks at the middle of each cell
ax.set_xticks(np.arange(data.shape[1])+0.5, minor=False)
ax.set_yticks(np.arange(data.shape[0])+0.5, minor=False)

# …
Run Code Online (Sandbox Code Playgroud)

python numpy matplotlib nan heatmap

2
推荐指数
1
解决办法
6355
查看次数