Ejemplo n.º 1
0
def kplot(kdata, new=True, axes=None, 
          colorup='r', colordown='g', width=0.6, alpha=1.0):
    """绘制K线图
    
    :param KData kdata: K线数据
    :param bool new:    是否在新窗口中显示,只在没有指定axes时生效
    :param axes:        指定的坐标轴
    :param colorup:     the color of the rectangle where close >= open
    :param colordown:   the color of the rectangle where close < open
    :param width:       fraction of a day for the rectangle width
    :param alpha:       the rectangle alpha level, 透明度(0.0~1.0) 1.0为不透明
    """
    if not kdata:
        print("kdata is None")
        return
    
    if not axes:
        axes = create_figure() if new else gca()
        
    OFFSET = width/2.0
    rfcolor = matplotlib.rcParams['axes.facecolor']
    for i in range(len(kdata)):
        record = kdata[i]
        open, high, low, close = record.openPrice, record.highPrice, record.lowPrice, record.closePrice
        if close>=open:
            color = colorup
            lower = open
            height = close-open
            rect = Rectangle(xy=(i-OFFSET, lower), width=width, height=height, facecolor=rfcolor, edgecolor=color)
        else:
            color = colordown
            lower = close
            height = open-close
            rect = Rectangle(xy=(i-OFFSET, lower), width=width, height=height, facecolor=color, edgecolor=color)

        vline1 = Line2D(xdata=(i, i), ydata=(low, lower), color=color, linewidth=0.5, antialiased=True)
        vline2 = Line2D(xdata=(i, i), ydata=(lower+height, high), color=color, linewidth=0.5, antialiased=True)
        rect.set_alpha(alpha)

        axes.add_line(vline1)
        axes.add_line(vline2)
        axes.add_patch(rect)
        
    title = get_draw_title(kdata)
    axes.set_title(title)  
    last_record = kdata[-1]
    color = 'r' if last_record.closePrice>kdata[-2].closePrice else 'g'
    text = u'%s 开:%.2f 高:%.2f 低:%.2f 收:%.2f 涨幅:%.2f%%' % (
        last_record.datetime.number/10000, 
        last_record.openPrice, last_record.highPrice,
        last_record.lowPrice,  last_record.closePrice,
        100*(last_record.closePrice-kdata[-2].closePrice)/kdata[-2].closePrice)
    axes.text(0.99,0.97, text, horizontalalignment='right', verticalalignment='top', 
              transform=axes.transAxes, color=color)
        
    axes.autoscale_view()
    axes.set_xlim(-1, len(kdata)+1)
    ax_set_locator_formatter(axes, kdata.getDatetimeList(), kdata.getQuery().kType)
Ejemplo n.º 2
0
def ibar(indicator, new=True, axes=None, 
         legend_on=False, text_on=False, text_color='k', label=None,
         width=0.4, color='r', edgecolor='r', 
         zero_on=False, *args, **kwargs):
    """绘制indicator柱状图
    
    :param Indicator indicator: Indicator实例
    :param axes:       指定的坐标轴
    :param new:        是否在新窗口中显示,只在没有指定axes时生效
    :param legend_on:  是否打开图例
    :param text_on:    是否在左上角显示指标名称及其参数
    :param text_color: 指标名称解释文字的颜色,默认为黑色
    :param str label:  label显示文字信息,text_on 及 legend_on 为 True 时生效
    :param zero_on:    是否需要在y=0轴上绘制一条直线
    :param width:      Bar的宽度
    :param color:      Bar的颜色
    :param edgecolor:  Bar边缘颜色
    :param args:       pylab plot参数
    :param kwargs:     pylab plot参数
    """
    if not indicator:
        print("indicator is None")
        return
    
    if not axes:
        axes = create_figure() if new else gca()

    if not label:
        label = "%s %.2f" % (indicator.long_name, indicator[-1])
    
    py_indicatr = [ None if x == constant.null_price else x for x in indicator]
    x = [i-0.2 for i in range(len(indicator))]
    y = py_indicatr
    
    axes.bar(x, py_indicatr, width=width, color=color, edgecolor=edgecolor, 
             *args, **kwargs)
        
    if legend_on:
        leg = axes.legend(loc='upper left')
        leg.get_frame().set_alpha(0.5)
        
    if text_on:
        if not axes.texts:
            axes.text(0.01,0.97, label, horizontalalignment='left', verticalalignment='top', 
                      transform=axes.transAxes, color=text_color)
        else:
            temp_str = axes.texts[0].get_text() + '  ' + label
            axes.texts[0].set_text(temp_str)
        
    if zero_on:
        ylim = axes.get_ylim()
        if ylim[0]<0<ylim[1]:
            axes.hlines(0,0,len(indicator))

    axes.autoscale_view()
    axes.set_xlim(-1, len(indicator)+1)
Ejemplo n.º 3
0
def save_scattered_image(z, id, name='scattered_image.jpg'):
    N = 17
    plotn = 2
    plt.figure(figsize=(8, 6))
    plt.scatter(z[:, 0],
                z[:, 1],
                c=id,
                marker='o',
                edgecolor='none',
                cmap=discrete_cmap(N, 'jet'))
    plt.colorbar(ticks=range(N))
    axes = plt.gca()
    axes.set_xlim([-4.5 * plotn, 4.5 * plotn])
    axes.set_ylim([-4.5 * plotn, 4.5 * plotn])
    plt.grid(True)
    plt.savefig(name)
Ejemplo n.º 4
0
def ibar(
    indicator,
    new=True,
    axes=None,
    legend_on=False,
    text_on=False,
    text_color='k',
    label=None,
    width=0.4,
    color='r',
    edgecolor='r',
    zero_on=False,
    *args,
    **kwargs
):
    """绘制indicator柱状图
    
    :param Indicator indicator: Indicator实例
    :param axes:       指定的坐标轴
    :param new:        是否在新窗口中显示,只在没有指定axes时生效
    :param legend_on:  是否打开图例
    :param text_on:    是否在左上角显示指标名称及其参数
    :param text_color: 指标名称解释文字的颜色,默认为黑色
    :param str label:  label显示文字信息,text_on 及 legend_on 为 True 时生效
    :param zero_on:    是否需要在y=0轴上绘制一条直线
    :param width:      Bar的宽度
    :param color:      Bar的颜色
    :param edgecolor:  Bar边缘颜色
    :param args:       pylab plot参数
    :param kwargs:     pylab plot参数
    """
    if not indicator:
        print("indicator is None")
        return

    if not axes:
        axes = create_figure() if new else gca()

    if not label:
        label = "%s %.2f" % (indicator.long_name, indicator[-1])

    py_indicatr = [None if x == constant.null_price else x for x in indicator]
    x = [i - 0.2 for i in range(len(indicator))]
    y = py_indicatr

    axes.bar(x, py_indicatr, width=width, color=color, edgecolor=edgecolor, *args, **kwargs)

    if legend_on:
        leg = axes.legend(loc='upper left')
        leg.get_frame().set_alpha(0.5)

    if text_on:
        if not axes.texts:
            axes.text(
                0.01,
                0.97,
                label,
                horizontalalignment='left',
                verticalalignment='top',
                transform=axes.transAxes,
                color=text_color
            )
        else:
            temp_str = axes.texts[0].get_text() + '  ' + label
            axes.texts[0].set_text(temp_str)

    if zero_on:
        ylim = axes.get_ylim()
        if ylim[0] < 0 < ylim[1]:
            axes.hlines(0, 0, len(indicator))

    axes.autoscale_view()
    axes.set_xlim(-1, len(indicator) + 1)
    k = indicator.get_context()
    if len(k) > 0:
        ax_set_locator_formatter(axes, k.get_date_list(), k.get_query().ktype)
Ejemplo n.º 5
0
def mkplot(kdata, new=True, axes=None, colorup='r', colordown='g', ticksize=3):
    """绘制美式K线图
    
    :param KData kdata: K线数据
    :param bool new:    是否在新窗口中显示,只在没有指定axes时生效
    :param axes:        指定的坐标轴
    :param colorup:     the color of the lines where close >= open
    :param colordown:   the color of the lines where close < open
    :param ticksize:    open/close tick marker in points
    """
    if not kdata:
        print("kdata is None")
        return

    if not axes:
        axes = create_figure() if new else gca()

    for t in range(len(kdata)):
        record = kdata[t]
        open, high, low, close = record.open, record.high, record.low, record.close
        color = colorup if close >= open else colordown

        vline = Line2D(xdata=(t, t), ydata=(low, high), color=color, antialiased=False)
        oline = Line2D(
            xdata=(t, t),
            ydata=(open, open),
            color=color,
            antialiased=False,
            marker=TICKLEFT,
            markersize=ticksize
        )
        cline = Line2D(
            xdata=(t, t),
            ydata=(close, close),
            color=color,
            antialiased=False,
            markersize=ticksize,
            marker=TICKRIGHT
        )

        axes.add_line(vline)
        axes.add_line(oline)
        axes.add_line(cline)

    title = get_draw_title(kdata)
    axes.set_title(title)
    last_record = kdata[-1]
    color = 'r' if last_record.close > kdata[-2].close else 'g'
    text = u'%s 开:%.2f 高:%.2f 低:%.2f 收:%.2f' % (
        last_record.date.number / 10000, last_record.open, last_record.high, last_record.low,
        last_record.close
    )
    axes.text(
        0.99,
        0.97,
        text,
        horizontalalignment='right',
        verticalalignment='top',
        transform=axes.transAxes,
        color=color
    )

    axes.autoscale_view()
    axes.set_xlim(-1, len(kdata) + 1)
    ax_set_locator_formatter(axes, kdata.get_date_list(), kdata.get_query().ktype)
Ejemplo n.º 6
0
def kplot(kdata, new=True, axes=None, colorup='r', colordown='g', width=0.6, alpha=1.0):
    """绘制K线图
    
    :param KData kdata: K线数据
    :param bool new:    是否在新窗口中显示,只在没有指定axes时生效
    :param axes:        指定的坐标轴
    :param colorup:     the color of the rectangle where close >= open
    :param colordown:   the color of the rectangle where close < open
    :param width:       fraction of a day for the rectangle width
    :param alpha:       the rectangle alpha level, 透明度(0.0~1.0) 1.0为不透明
    """
    if not kdata:
        print("kdata is None")
        return

    if not axes:
        axes = create_figure() if new else gca()

    OFFSET = width / 2.0
    rfcolor = matplotlib.rcParams['axes.facecolor']
    for i in range(len(kdata)):
        record = kdata[i]
        open, high, low, close = record.open, record.high, record.low, record.close
        if close >= open:
            color = colorup
            lower = open
            height = close - open
            rect = Rectangle(
                xy=(i - OFFSET, lower),
                width=width,
                height=height,
                facecolor=rfcolor,
                edgecolor=color
            )
        else:
            color = colordown
            lower = close
            height = open - close
            rect = Rectangle(
                xy=(i - OFFSET, lower),
                width=width,
                height=height,
                facecolor=color,
                edgecolor=color
            )

        vline1 = Line2D(
            xdata=(i, i), ydata=(low, lower), color=color, linewidth=0.5, antialiased=True
        )
        vline2 = Line2D(
            xdata=(i, i),
            ydata=(lower + height, high),
            color=color,
            linewidth=0.5,
            antialiased=True
        )
        rect.set_alpha(alpha)

        axes.add_line(vline1)
        axes.add_line(vline2)
        axes.add_patch(rect)

    title = get_draw_title(kdata)
    axes.set_title(title)
    last_record = kdata[-1]
    color = 'r' if last_record.close > kdata[-2].close else 'g'
    text = u'%s 开:%.2f 高:%.2f 低:%.2f 收:%.2f 涨幅:%.2f%%' % (
        last_record.date.number / 10000, last_record.open, last_record.high, last_record.low,
        last_record.close, 100 * (last_record.close - kdata[-2].close) / kdata[-2].close
    )
    axes.text(
        0.99,
        0.97,
        text,
        horizontalalignment='right',
        verticalalignment='top',
        transform=axes.transAxes,
        color=color
    )

    axes.autoscale_view()
    axes.set_xlim(-1, len(kdata) + 1)
    ax_set_locator_formatter(axes, kdata.get_date_list(), kdata.get_query().ktype)
Ejemplo n.º 7
0
Archivo: rgr1.py Proyecto: AnMnv/test
    for j in np.arange(xset+1):
        xline.append(delta*j)
        yline.append(delta*i)
    X.append(xline)
    Y.append(yline)

U = Ex
V = Ey

fig, ax = plt.subplots()
widths = np.linspace(0, 1, V.size)
w = 0.003
plt.quiver(X, Y, V, U, width = w)
plt.title(u'Картина поля за допомогою векторів напруженості електричного поля')
axes = plt.gca()
axes.set_xlim([-0.1,6.1])
axes.set_ylim([-0.1,3.1])
fig.savefig('~/Desktop/ТП/1.png')
plt.close(fig)

fig, ax = plt.subplots()
CS = ax.contour(X, Y, a, levels = np.arange(-1, 3, 0.2))
ax.clabel(CS, inline=True, fontsize=10)
ax.set_title(u'Картина поля за допомогою еквіпотенціалей')
ax.set_xlim([-0.1,6.1])
ax.set_ylim([-0.1,3.1])
plt.show()

fig = plt.figure()
ax = fig.gca(projection='3d')
CS = ax.plot_surface(X, Y, a, cmap = cm.coolwarm)
Ejemplo n.º 8
0
def iplot(indicator,
          new=True,
          axes=None,
          legend_on=False,
          text_on=False,
          text_color='k',
          zero_on=False,
          label=None,
          *args,
          **kwargs):
    """绘制indicator曲线
    
    :param Indicator indicator: indicator实例
    :param axes:            指定的坐标轴
    :param new:             是否在新窗口中显示,只在没有指定axes时生效
    :param legend_on:       是否打开图例
    :param text_on:         是否在左上角显示指标名称及其参数
    :param text_color:      指标名称解释文字的颜色,默认为黑色
    :param zero_on:         是否需要在y=0轴上绘制一条直线
    :param str label:       label显示文字信息,text_on 及 legend_on 为 True 时生效
    :param args:            pylab plot参数
    :param kwargs:          pylab plot参数,如:marker(标记类型)、
                             markerfacecolor(标记颜色)、
                             markeredgecolor(标记的边缘颜色)
    """
    if not indicator:
        print("indicator is None")
        return

    if not axes:
        axes = create_figure() if new else gca()

    if not label:
        label = "%s %.2f" % (indicator.long_name, indicator[-1])

    py_indicatr = [None if x == constant.null_price else x for x in indicator]
    axes.plot(py_indicatr, '-', label=label, *args, **kwargs)

    if legend_on:
        leg = axes.legend(loc='upper left')
        leg.get_frame().set_alpha(0.5)

    if text_on:
        if not axes.texts:
            axes.text(0.01,
                      0.97,
                      label,
                      horizontalalignment='left',
                      verticalalignment='top',
                      transform=axes.transAxes,
                      color=text_color)
        else:
            temp_str = axes.texts[0].get_text() + '  ' + label
            axes.texts[0].set_text(temp_str)

    if zero_on:
        ylim = axes.get_ylim()
        if ylim[0] < 0 < ylim[1]:
            axes.hlines(0, 0, len(indicator))

    axes.autoscale_view()
    axes.set_xlim(-1, len(indicator) + 1)
Ejemplo n.º 9
0


#axes.set_title('Geant2012',color='Black',size=20)
# axes[1].set_title('k=32',color='#77933C')
# axes[2].set_title('k=Geant2012',color='#77933C')
axes.set_yscale('log')
#axes[0].set_yscale('log')
#axes[1].get_yaxis().set_ticks([])
#axes[2].set_yscale('log')
axes.set_ylabel('Time (ms)',size = 50, color='Black')
axes.set_xlabel('Functions\' Chain Size',size = 50, color='Black')

axes.yaxis.grid(b=True, which='major', color='dimgray', linestyle='--',linewidth = 5.0)
axes.set_ylim([1,80000])
axes.set_xlim([0,16])
axes.set_xticks([1.5, 4.5, 7.5,10.5,13.5])
axes.set_xticklabels(['3', '4', '5','6','7'],color='black',size=35)
axes.tick_params(axis='y', colors='black',size=35)
    
for tic in axes.yaxis.get_major_ticks():
    tic.label.set_fontsize(35)
    
#for tic in axes[2].yaxis.get_major_ticks():
#    tic.label1On = tic.label2On = False
# set axes limits and labels


hB, = axes.plot([0,0],'g-',linewidth = 3.0)
hR, = axes.plot([0,0],'-',color='#C00000', linewidth = 3.0)
legend = legend((hB, hR),('Gavel', 'Ravel'),loc=(0.85, .7), labelspacing=0.1)
Ejemplo n.º 10
0
def ibar(indicator,
         axes=None,
         width=0.4,
         color='r',
         edgecolor='r',
         new=True,
         legend_on=False,
         text_on=False,
         text_color='k',
         label=None,
         zero_on=False,
         *args,
         **kwargs):
    """绘制indicator曲线
    indicator: Indicator实例
    axes: 指定的坐标轴
    new: 是否在新窗口中显示,只在没有指定axes时生效
    legend_on : 是否打开图例
    text_on: 是否在左上角显示指标名称及其参数
    text_color: 指标名称解释文字的颜色,默认为黑色
    zero_on: 是否需要在y=0轴上绘制一条直线
    *args, **kwargs : pylab bar参数
    """
    if not indicator:
        print("indicator is None")
        return

    if not axes:
        axes = create_one_axes_figure() if new else gca()

    if not label:
        label = "%s %.2f" % (indicator.long_name, indicator[-1])

    py_indicatr = [None if x == constant.null_price else x for x in indicator]
    x = [i - 0.2 for i in range(len(indicator))]
    y = py_indicatr

    axes.bar(x,
             py_indicatr,
             width=width,
             color=color,
             edgecolor=edgecolor,
             *args,
             **kwargs)

    if legend_on:
        leg = axes.legend(loc='upper left')
        leg.get_frame().set_alpha(0.5)

    if text_on:
        if not axes.texts:
            axes.text(0.01,
                      0.97,
                      label,
                      horizontalalignment='left',
                      verticalalignment='top',
                      transform=axes.transAxes,
                      color=text_color)
        else:
            temp_str = axes.texts[0].get_text() + '  ' + label
            axes.texts[0].set_text(temp_str)

    if zero_on:
        ylim = axes.get_ylim()
        if ylim[0] < 0 < ylim[1]:
            axes.hlines(0, 0, len(indicator))

    axes.autoscale_view()
    axes.set_xlim(-1, len(indicator) + 1)