如何在matplotlib中单独设置标记颜色

时间:2016-06-10 12:41:05

标签: python multidimensional-array matplotlib charts beautifulsoup

2D线有问题。我想要做的是绘制一个具有此类信息的图表:

TEST1   1 0 0  
TEST2   1 1 1
TEST3   0 0 1

当结果中有1时,应该有一个绿色气泡,当为零时 - 红色气泡。 我试过(给出matplotlib的例子):
http://matplotlib.org/examples/lines_bars_and_markers/marker_fillstyle_reference.html

但是,我无法理解如何根据其值来绘制每个气泡 尝试制作3个不同的阵列并在X轴上进行偏移,但不知何故它不起作用...有什么想法我怎么能这样做?
添加我试图编写的一些代码:

from matplotlib.lines import Line2D


points = np.ones(2)  # Draw 3 points for each line
print points
text_style = dict(horizontalalignment='right', verticalalignment='center',
                  fontsize=16, fontdict={'family': 'monospace'})
marker_style_red = dict(color='red', linestyle=':', marker='o',
                    markersize=20, markerfacecoloralt='gray')
marker_style_green = dict(color='green', linestyle=':', marker='o',
                    markersize=20, markerfacecoloralt='gray')


def format_axes(ax):
    ax.margins(0.2)
    ax.set_axis_off()


def nice_repr(text):
    return repr(text).lstrip('u')


fig, ax = plt.subplots()


y_ax = 1     
for y in data2:

    ax.text(-0.5, y_ax, nice_repr(y[6]) , **text_style)

    if y[0] == 0:
        ax.plot(y_ax * points[1], fillstyle='full', **marker_style_red)
    elif y[0] == 1:
        ax.plot(y_ax * points[1], fillstyle='full', **marker_style_green)
    y_ax += 1
    format_axes(ax)

plt.show()

但是这不起作用,因为气泡不会根据数组中的值而改变 添加照片我应该如何看待它:enter image description here

并且不知道如何将我的数组数据作为表格形式,但根据数据使用颜色的气泡。我应该创建大量的1D线和偏移吗?如果我使用散点图,它可能适用于气泡,但如何显示气泡旁边的所有其他数据?或者我应该使用beautifulsoup命令并以某种方式添加css以将标签显示为泡泡?

0 个答案:

没有答案