import pandas as pd
from wordcloud import WordCloud
import matplotlib.pyplot as plt
try:
# Read CSV file
file_path = open("D:/luolan/2018-2022年一二产业增加值.csv")
data = pd.read_csv(file_path)
# Get region data
regions = data['地区']
# Generate word cloud
text = ' '.join(region for region in regions)
wordcloud = WordCloud(background_color="white", width=800, height=400).generate(text)
# Set background image
background = plt.imread("D:/luolan/background1.png")
# Plot word cloud
fig, ax = plt.subplots(figsize=(10, 5))
ax.imshow(wordcloud, interpolation="bilinear")
ax.set_axis_off()
plt.imshow(background, alpha=0.9)
plt.show()
except Exception as e:
print("Error occurred:", str(e))
#文件如图