# Generate the pivot table, containing all variables table = pd.pivot_table(df2, values=['Valuation ($B)'], index=['Total Raised ($B)'], columns=['Industry']) # Generated correlation matrix corr = table.corr() # Drawing heat map sns.heatmap(corr, cmap='coolwarm') plt.show() plt.save('11')设置图片保存到桌面
时间: 2023-12-01 19:03:12 浏览: 27
你可以使用以下代码将图片保存到桌面:
```python
import os
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# Generate the pivot table, containing all variables
table = pd.pivot_table(df2, values=['Valuation ($B)'], index=['Total Raised ($B)'], columns=['Industry'])
# Generated correlation matrix
corr = table.corr()
# Drawing heat map
sns.heatmap(corr, cmap='coolwarm')
plt.show()
# Save figure to desktop
desktop_path = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop') # Get desktop path
plt.savefig(os.path.join(desktop_path, '11.png'))
```
这段代码会将生成的图片保存为 "11.png" 并放在你的桌面上。如果你需要保存为其他格式,只需将 `.png` 替换为其他格式的扩展名即可。
相关问题
# 补全下面的代码,产生词云 word_cloud = ...(cut_text)
补全代码如下:
```python
word_cloud = WordCloud(font_path=fontpath, background_color='white', mask=background_image).generate(' '.join(filtered_words))
```
以上代码使用`WordCloud`类创建了一个词云对象`word_cloud`。在创建词云对象时,通过传入`font_path`参数指定了字体文件的路径,`background_color`参数设置词云的背景颜色为白色,`mask`参数指定了词云的背景图片。
然后,使用`.generate()`方法生成词云,传入的参数是使用空格连接起来的分词结果`' '.join(filtered_words)`。
请确保已经正确导入了`WordCloud`类,并正确设置了字体文件路径、背景颜色和背景图片。
from skimage.morphology import skeletonize_3d from skimage import data # Load the 3D data points data = data.binary_blobs(length=100, blob_size_fraction=0.1, n_dim=3) # Convert the data points to a binary image binary_image = data.astype(bool) # Generate the distance map distance_map = ndimage.distance_transform_edt(binary_image) # Threshold the distance map thresholded_distance_map = (distance_map > 0) & (distance_map < 10) # Skeletonize the thresholded distance map skeleton = skeletonize_3d(thresholded_distance_map)对这段代码采用matplotlib进行可视化
好的,您可以尝试使用以下代码来可视化这段代码生成的三维骨架图像:
```python
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Plot the binary image
x, y, z = binary_image.nonzero()
ax.scatter(x, y, z, zdir='z', c='red')
# Plot the skeleton
verts, faces, _, _ = measure.marching_cubes_lewiner(skeleton, 0)
mesh = Poly3DCollection(verts[faces], alpha=0.1)
face_color = [0.5, 0.5, 1]
mesh.set_facecolor(face_color)
ax.add_collection3d(mesh)
ax.set_xlim(0, binary_image.shape[0])
ax.set_ylim(0, binary_image.shape[1])
ax.set_zlim(0, binary_image.shape[2])
plt.show()
```
这段代码使用了matplotlib库中的3D可视化功能,将原始的二进制图像和骨架图像在三维空间中显示出来。其中,红色的点表示二进制图像中的非零点,蓝色的线条表示骨架图像。