# # 基本柱状图 # import matplotlib.pyplot as plt # # plt.style.use('seaborn-darkgrid') # # # 设置字体,中文为SimSun,英文为Times New Roman # # plt.rcParams['font.family'] = '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.savefig("js.jpg") # # 显示图形 # plt.show()
# # 条形图 # import matplotlib.pyplot as plt # # plt.style.use('seaborn-darkgrid') # # # 设置字体,中文为SimSun,英文为Times New Roman # # plt.rcParams['font.family'] = 'SimSun' # # 数据 # x = ['A','B','C','D'] # y = [10, 20, 15, 25] # # 绘制柱状图 # plt.barh(x, y) # # 添加标题和标签 # plt.title('123456', fontsize=16) # plt.xlabel('1234', fontsize=16) # plt.ylabel('5678', fontsize=16) # plt.savefig("js.jpg") # # 显示图形 # plt.show()
# # 折线图 # import matplotlib.pyplot as plt # # plt.style.use('seaborn-darkgrid') # # # 设置字体,中文为SimSun,英文为Times New Roman # # plt.rcParams['font.family'] = 'SimSun' # # 数据 # x = [1,2,3,4] # y = [10, 20, 15, 25] # # 绘制柱状图 # plt.plot(x, y) # # 添加标题和标签 # plt.title('123456', fontsize=16) # plt.xlabel('1234', fontsize=16) # plt.ylabel('5678', fontsize=16) # plt.savefig("js.jpg") # # 显示图形 # plt.show()
# # #动态图 # import numpy as np # from matplotlib import pyplot as plt # from matplotlib import animation # import matplotlib # fig = plt.figure() # ax=plt.axes(xlim=(0,2),ylim=(-2,2)) # line, =ax.plot([],[],lw=2) # def init(): # line.set_data([],[]) # return line, # def animate(i): # x=np.linspace(0,2,1000) # y=np.sin(2 * np.pi * (x - 0.01 * i)) # line.set_data(x,y) # return line, # anim=animation.FuncAnimation(fig,animate,init_func=init,frames=200,interval=20,blit=True) # anim.save('sinAim.gif',fps=75,writer='pillow') # plt.savefig("jl.jpg") # 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("aaa.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()
创建一个HTML(在同一个目录下)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <img src="jj.jpg"> <img src="jp.jpg"> <img src="js.jpg"> <img src="jl.jpg"> <img src="heart.jpg"> </body> </html>