python可视化不在508

# # 基本柱状图
#
# import matplotlib.pyplot as plt
# # import seaborn as sns
#
# # 设置绘图风格
# # 法2:
# plt.style.use('seaborn-darkgrid')
#
# # 设置字体,中文为SimSun,英文为Times New Roman
# # 法1:
# plt.rcParams['font.family'] = 'Times New Roman, SimSun'
#
# # 数据
# x = ['A', 'B', 'C', 'D']
# y = [10, 20, 15, 25]
#
# # 绘制柱状图
# plt.bar(x, y)
#
# # 添加标题和标签
# plt.title('123456', fontsize=16)
# plt.xlabel('1234', fontsize=16)
# plt.ylabel('5678', fontsize=16)
#
# # 显示图形
# plt.show()

# 叠堆柱状图
# from matplotlib import pyplot as plt
# import numpy as np
# import matplotlib
#
# # 参数设置
# plt.style.use('seaborn-darkgrid')
# matplotlib.rcParams['axes.unicode_minus']=False
# plt.rcParams['font.family'] = ' SimSun'
# matplotlib.rcParams['font.sans-serif']=['SimHei']
# # 数据
# classes = ['一班', '二班', '三班', '四班', '五班']
# language = np.array([87, 85, 89, 81, 78])
# math = np.array([85, 98, 84, 79, 82])
# english = np.array([83, 85, 82, 87, 78])
# width = 0.3
#
# # 绘图
# plt.bar(classes, language, color='gold', label="语文", bottom=math + english, width=width)
# plt.bar(classes, math, color='silver', label='数学', bottom=english, width=width)
# plt.bar(classes, english, color='#A0522D', label='英语', width=width)
#
# # 设置y轴标签,图例和文本值
# plt.ylabel('平均分')
# plt.legend(loc='upper right')
# for i in range(len(classes)):
#         max_y = english[i] + math[i] + language[i]
#         plt.text(classes[i], max_y, max_y, va="bottom", ha="center")
#
# plt.show()

# 横向柱状图
#
# import matplotlib.pyplot as plt
# # import seaborn as sns
# # # 设置绘图风格
#
# # 法2:
# plt.style.use('seaborn-darkgrid')
#
# # 设置字体,中文为SimSun,英文为Times New Roman
# # 法1:
# plt.rcParams['font.family'] = ' SimSun'
#
# # 数据
# x = ['A', 'B', 'C', 'D']
# y = [10, 20, 15, 25]
#
# # 绘制柱状图
# plt.barh(x, y)
#
# # 添加标题和标签
# plt.title('柱状图示例', fontsize=16)
# plt.xlabel('类别', fontsize=16)
# plt.ylabel('数值', fontsize=16)
#
# # 显示图形
# plt.show()


# 折线图
#
# import matplotlib.pyplot as plt
#
# # 月份
# x1 = ['2017-01', '2017-02', '2017-03', '2017-04', '2017-05', '2017-06', '2017-07', '2017-08',
#             '2017-09', '2017-10', '2017-11', '2017-12']
# # 体重
# y1 = [86, 85, 84, 80, 75, 70, 70, 74, 78, 70, 74, 80]
#
# # 设置画布大小
# plt.figure(figsize=(10, 7))
# # 设置字体
# font1 = {'family': 'Times New Roman', 'weight': 'normal', 'size': 14}
# plt.rc('font', **font1)
# # 绘图
# plt.plot(x1, y1, label='weight changes', linewidth=3, color='r', marker='o',
#                 markerfacecolor='blue', markersize=14)
# # 标题
# plt.title("my weight", fontproperties=font1)
# # 横坐标描述
# plt.xlabel('month', fontproperties=font1)
# # 纵坐标描述
# plt.ylabel('weight', fontproperties=font1)
# # 设置数字标签
# for a, b in zip(x1, y1):
#         plt.text(a, b + 0.5, b, ha='center', va='bottom', fontproperties=font1)
# # 设置图例
# plt.legend()
# plt.show()


# #动态图
# import matplotlib.pyplot as plt
# import numpy as np
# import time
# # 创建一个图形窗口
# fig, ax = plt.subplots()
# # 初始化 x 和 y 数据
# x = np.random.rand(100)
# y = np.random.rand(100)
# # 绘制初始的散点
# scatter = ax.scatter(x, y)
# # 动态更新函数
# def update(frame):
#     x = np.random.rand(100)
#     y = np.random.rand(100)
#     scatter.set_offsets(np.c_[x, y])  # 更新散点的位置
#     return scatter,
# # 使用 FuncAnimation 实现动态效果
# from matplotlib.animation import FuncAnimation
# ani = FuncAnimation(fig, update, frames=np.arange(0, 100), interval=100)  # 每隔 100 毫秒更新一次
# plt.show()

# 词云
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from wordcloud import WordCloud, ImageColorGenerator
text = '''awese llow pat of Taoine emeges from a total eclme yellow palnet My teacher, Miss Wang, My home town is a beautiful place. It stands beside a wide river and is rich in fish and rice.  But in the old days it was a poor and backward little town. Many people had no work. They lived a hard life.  In 1949 my hometown was liberated. Since then great changes have taken place there. The streets have been widened. Factories, schools, hospitals, cinemas and theatres have sprung up one after another. The life of the people is greatly improved.www.t262.com  I love my hometown. All the more I love its people. They are working hard so as to make it still richer and more beautiful. helped me a lot in my middle school life. She is a kind easygoing woman. I must thank her for making a confident girl.  I used to be a shy and unconfident girl. Mrs. Wang noticed me. She took good care of me and encouraged me to join the school speech contest. Of course, I failed. But Mrs. Wang cheered me up and said every man is the architect of his own future.  From then on, I practiced every day. It goes without saying “No pain, no gain.” I won the contest in the second term. In my opinion, teachers are the same as gardeners and they volunteer today and gain tomorrow. Not only can they teach knowledge but also they can teach students how to be a successful man.  Thank you, Mrs. Wang. You make a duck become a beautiful swan. I want to be a teacher that as same as you in the future. of Tatooine emerges from a total eclipseawesome yellow palnet of Tatooine emerges from a total eclipseawesome yellow palnet of Tatooine emerges from a total eclipseawesome yellow palnet of Tatooine emerges from a total eclipse'''
color_mask = np.array(Image.open("ccc.jpg"))#把图片复制粘贴到pythonProject下
wc = WordCloud( mask=color_mask,background_color='white').generate(text)
plt.imshow(wc, interpolation="bilinear")
plt.axis("off")
plt.savefig("heart.jpg")
plt.show()


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值