2019-03-01

2019-03-01  本文已影响0人  奥体一圈
# 导入必要模块
import pandas as pd
import numpy as np
from sqlalchemy import create_engine
import matplotlib
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
import pymysql
#
# # 初始化数据库连接,使用pymysql模块
# # MySQL的用户:root, 密码:147369, 端口:3306,数据库:mydb
# engine = create_engine('mysql+pymysql://root:333@localhost:3306/chat')
#
# # 查询语句,选出employee表中的所有数据
# sql = '''
#       select * from chat.aa limit 10;
#       '''
#
# # read_sql_query的两个参数: sql语句, 数据库连接
# df = pd.read_sql_query(sql, engine)
#
# # 输出employee表的查询结果
# print(df)
#
# #
# # qushi=np.dtype([('Y','S45'),('M','S45'),('Sale','S45')])
# # data=np.fromiter(df,dtype=qushi,count=-1)
# plt.bar(df['time'],df['price'],align='center')
# plt.title(u'2014趋势')
# plt.xlabel(u'月份')
# plt.ylabel(u'价格')
# plt.xticks(df['price'])
# plt.show()
#
#----------------------------------------------------
# plt.figure(figsize=(6, 6))
# n = 8
# X = np.arange(n) + 1
# # X是1,2,3,4,5,6,7,8,柱的个数
# # numpy.random.uniform(low=0.0, high=1.0, size=None), normal
# # uniform均匀分布的随机数,normal是正态分布的随机数,0.5-1均匀分布的数,一共有n个
# Y1 = np.random.uniform(0.5, 1.0, n)
# Y2 = np.random.uniform(0.5, 1.0, n)
# print(X,'X')
# print(Y2,'y2')
# #plt.bar(X, Y1, width=0.35, facecolor='lightskyblue', edgecolor='white')
# # width:柱的宽度
# #plt.bar(X + 0.35, Y2, width=0.35, facecolor='yellowgreen', edgecolor='white')
# plt.bar(X,Y1)
#
# #plt.pie(X)
# # 水平柱状图plt.barh,属性中宽度width变成了高度height
# # 打两组数据时用+
# # facecolor柱状图里填充的颜色
# # edgecolor是边框的颜色
# # 想把一组数据打到下边,在数据前使用负号
# # plt.bar(X, -Y2, width=width, facecolor='#ff9999', edgecolor='white')
# # 给图加text
# for x, y in zip(X, Y1):
#     plt.text(x + 0.3, y + 0.05, '%.2f' % y, ha='center', va='bottom')
#
# for x, y in zip(X, Y2):
#     plt.text(x + 0.6, y + 0.05, '%.2f' % y, ha='center', va='bottom')
# plt.ylim(0, +1.25)
# plt.show()
#matplotlib.rcParams[savefig.dpi]
# x = np.arange(1, 11)
#
# fig = plt.figure(1)
# ax1 = plt.subplot(2, 1, 1)
# ax2 = plt.subplot(2, 1, 2)
# l1, = ax1.plot(x, x*x, 'r')             #这里关键哦
# l2, = ax2.plot(x, x*x, 'b')           # 注意
#
# plt.legend([l1, l2], ['first', 'second'], loc = 'upper right')             #其中,loc表示位置的;
#
# plt.show()
#

x1 = [1, 2, 3, 4, 5]# Make x, y arrays for each graph
y1 = [1, 4, 9, 16, 25]
x2 = [1, 2, 4, 6, 8]
y2 = [2, 4, 8, 12, 16]
plot1 = plt.plot(x1, y1,'r')# use pylab to plot x and y : Give your plots names
plot2 = plt.plot(x2, y2,'go')
plt.title('Plot of y vs. x')# give plot a title
plt.xlabel('x axis')# make axis labels
plt.ylabel('y axis')
plt.xlim(0.0, 9.0)# set axis limits
plt.ylim(0.0, 30.)
plt.legend(['red line', 'green circles'], loc = 0, ncol = 2)# make legend
plt.show()# show the plot on the screen
上一篇下一篇

猜你喜欢

热点阅读