Exemplo n.º 1
0
def setup_axes(fig, rect):
    ax = axislines.Subplot(fig, rect)
    fig.add_subplot(ax)

    ax.set_yticks([0.2, 0.8])
    ax.set_xticks([0.2, 0.8])

    return ax
Exemplo n.º 2
0
def setup_axes(fig, rect):

    ax = axislines.Subplot(fig, rect)
    fig.add_subplot(ax)

    ax.set_yticks([0.2, 0.8])
    #ax.set_yticklabels(["short", "loooong"])
    ax.set_xticks([0.2, 0.8])
    #ax.set_xticklabels([r"$\frac{1}{2}\pi$", r"$\pi$"])

    return ax
Exemplo n.º 3
0
def main(table_name):
    print("table_name" + table_name)
    fig = plt.figure(1, figsize=(10, 6))
    fig.subplots_adjust(bottom=0.2)

    #1. 连接数据库
    conn = ConnDB()

    #  子图1
    ax1 = axislines.Subplot(fig, 211)
    fig.add_subplot(ax1)
    results = []
    results = SelectDB(conn, table_name)
    for row in results:
        # print(row[3])
        ax1.scatter(row[1], row[3], s=int(row[2]) / 10)  # 第三个变量表明根据收入气泡的大
    #"豆瓣电影年份-评分图", FontProperties='STKAITI', fontsize=10)

    # # 子图2
    ax2 = axislines.Subplot(fig, 223)
    fig.add_subplot(ax2)

    results = []
    results = CountDateDB(conn, table_name)
    labels = [x[0] for x in results]
    # 每个标签占多大,会自动去算百分比
    sizes = [x[1] for x in results]
    patches, l_text, p_text = plt.pie(sizes,
                                      labels=labels,
                                      labeldistance=1.1,
                                      autopct='%3.1f%%',
                                      shadow=False,
                                      startangle=90,
                                      pctdistance=0.6)
    for t in l_text:
        t.set_size = (30)
    for t in p_text:
        t.set_size = (20)
    # 设置x,y轴刻度一致,这样饼图才能是圆的
    plt.axis('equal')
    plt.legend()
    plt.suptitle("豆瓣电影年份-饼图", FontProperties='STKAITI', fontsize=10)

    # # 子图3
    ax2 = axislines.Subplot(fig, 224)
    fig.add_subplot(ax2)
    results = []
    results = CountTimeDB(conn, table_name)
    labels = [x[0] for x in results]
    # 每个标签占多大,会自动去算百分比
    sizes = [x[1] for x in results]
    patches, l_text, p_text = plt.pie(sizes,
                                      labels=labels,
                                      labeldistance=1.1,
                                      autopct='%3.1f%%',
                                      shadow=False,
                                      startangle=90,
                                      pctdistance=0.6)
    for t in l_text:
        t.set_size = (30)
    for t in p_text:
        t.set_size = (20)
    # 设置x,y轴刻度一致,这样饼图才能是圆的
    plt.axis('equal')
    plt.legend()
    plt.suptitle("豆瓣电影时长-饼图", FontProperties='STKAITI', fontsize=10)

    plt.show()

    CloseDB(conn)
Exemplo n.º 4
0
import matplotlib.pyplot as plt
from pylab import mpl
#plt.rcParams['font.sans-serif'] = ['YaHei Consolas Hybrid'] # 用来正常显示中文标签
#plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
import mpl_toolkits.axisartist.axislines as axislines

fig = plt.figure(1, figsize=(10, 6))
fig.subplots_adjust(bottom=0.2)

# 子图1
ax1 = axislines.Subplot(fig, 131)
fig.add_subplot(ax1)
# for axis in ax1.axis.values():
#     axis.major_ticks.set_tick_out(True) # 标签全部在外部
ax1.axis[:].major_ticks.set_tick_out(True)  # 这句和上面的for循环功能相同
ax1.axis["left"].label.set_text("子图1 -left标签")  # 显示在左边
# 设置刻度
ax1.set_yticks([2, 4, 6, 8])
ax1.set_xticks([0.2, 0.4, 0.6, 0.8])

# 子图2
ax2 = axislines.Subplot(fig, 132)
fig.add_subplot(ax2)
ax2.set_yticks([1, 3, 5, 7])
ax2.set_yticklabels(('one', 'two', 'three', 'four', 'five'))  # 不显示‘five’
ax2.set_xlim(5, 0)  # X轴刻度
ax2.axis["left"].set_axis_direction("right")
ax2.axis["left"].label.set_text("子图2 -left标签")  # 显示在右边
ax2.axis["bottom"].set_axis_direction("top")
ax2.axis["right"].set_axis_direction("left")
ax2.axis["top"].set_axis_direction("bottom")
Exemplo n.º 5
0
def Get_Movie_Rate(url):
    html = requests.get(url).content
    page = etree.HTML(html)
    title = (page.xpath("//*[@id='content']/h1/span[1]/text()")[0]).split()[0]
    info = page.xpath("//*[@id='info']")[0]
    movie = {}
    movie['director'] = info.xpath("./span[1]/span[2]/a/text()")[0]
    movie['screenwriter'] = info.xpath("./span[2]/span[2]/a/text()")[0]
    movie['actors'] = '/'.join(info.xpath("./span[3]/span[2]/a/text()"))
    movie['type'] = '/'.join(
        info.xpath("./span[@property='v:genre']/"
                   "text()"))
    movie['initialReleaseDate'] = '/'. \
        join(info.xpath(".//span[@property='v:initialReleaseDate']/text()"))
    movie['runtime'] = \
        info.xpath(".//span[@property='v:runtime']/text()")[0]

    star = page.xpath("//*[@id='interest_sectl']")[0]
    movie['five_star'] = re.findall(
        r"\d+\.?\d*",
        star.xpath("./div[1]/div[3]/div[1]/span[2]/text()")[0])
    movie['four_star'] = re.findall(
        r"\d+\.?\d*",
        star.xpath("./div[1]/div[3]/div[2]/span[2]/text()")[0])
    movie['three_star'] = re.findall(
        r"\d+\.?\d*",
        star.xpath("./div[1]/div[3]/div[3]/span[2]/text()")[0])
    movie['two_star'] = re.findall(
        r"\d+\.?\d*",
        star.xpath("./div[1]/div[3]/div[4]/span[2]/text()")[0])
    movie['one_star'] = re.findall(
        r"\d+\.?\d*",
        star.xpath("./div[1]/div[3]/div[5]/span[2]/text()")[0])
    print(movie)

    #画图
    fig = plt.figure(1, figsize=(10, 6))
    fig.subplots_adjust(bottom=0.2)
    ax2 = axislines.Subplot(fig, 111)
    fig.add_subplot(ax2)

    labels = ['一星', '两星', '三星', '四星', '五星']
    # 每个标签占多大,会自动去算百分比
    explode = [0, 0, 0, 0, 0.05]  # 0.1 凸出这部分,
    sizes = [
        movie['one_star'], movie['two_star'], movie['three_star'],
        movie['four_star'], movie['five_star']
    ]
    patches, l_text, p_text = plt.pie(sizes,
                                      labels=labels,
                                      explode=explode,
                                      labeldistance=1.1,
                                      autopct='%3.1f%%',
                                      shadow=False,
                                      startangle=90,
                                      pctdistance=0.6)
    for t in l_text:
        t.set_size = (30)
    for t in p_text:
        t.set_size = (20)
    # 设置x,y轴刻度一致,这样饼图才能是圆的
    plt.axis('equal')
    plt.legend()
    plt.suptitle(title + "豆瓣评分-饼图", FontProperties='STKAITI', fontsize=24)

    plt.show()
Exemplo n.º 6
0

def CloseDB(conn):
    conn.close()


if __name__ == '__main__':

    fig = plt.figure(1, figsize=(10, 6))
    fig.subplots_adjust(bottom=0.2)

    #1. 连接数据库
    conn = ConnDB()

    #  子图1
    ax1 = axislines.Subplot(fig, 211)
    fig.add_subplot(ax1)
    results = []
    results = SelectDB(conn)
    for row in results:
        # print(row[3])
        ax1.scatter(row[1], row[3], s=int(row[2]) / 10)  # 第三个变量表明根据收入气泡的大
    #"豆瓣电影年份-评分图", FontProperties='STKAITI', fontsize=10)

    # # 子图2
    ax2 = axislines.Subplot(fig, 223)
    fig.add_subplot(ax2)

    results = []
    results = CountDateDB(conn)
    labels = [x[0] for x in results]