Giter Site home page Giter Site logo

confused-pie-plots's People

Contributors

dterg avatar

Watchers

 avatar  avatar

confused-pie-plots's Issues

Adding class name in to centre of pie plot and correcting legend

Hi,

Thank you for this alternative to a confusion matrix i think its great! I have implemented the code for a confusion matrix generate which contains only one row and column of class (age)..

I am getting a slightly odd plot and was wondering if you could point me in the right direction for correcting it.

The issues:

figure not plotting class name in the middle of the pie-plot. Would like to remove the titles of each plot and simply add them to the middle of the plot (similar to p60, but with the right class name [p3,p15 etc...]

And the for the full legend to plot! I am unsure as to where the error is in my code! any help would be much appreciated. thanks!

code

confMat = np.array(fullConfMat.ix[1:,1:])
ageNames = fullConfMat[0][1:].tolist()

nAges = len(ageNames)
nCols = np.shape(ageNames)[0]

nRows = 1
idx = []

parentDict = dict((el,0) for el in ageNames)
for iParent, parent in enumerate(ageNames):
    for i, j in enumerate(ageNames):
        if j == parent:
            idx.append(i)
    parentDict[parent] = idx
    iUpperLvlClasses = [ageNames[i] for i in idx]
    iLevelnClasses = np.shape(np.unique(iUpperLvlClasses))[0]
    idx = []

if iLevelnClasses > nRows:
        nRows = iLevelnClasses

legendRowsNeeded = int(np.ceil(float(nAges) / float(nCols)))
totalRows = nRows + legendRowsNeeded

heightRatios = []
[heightRatios.append(3) for x in range(0,nRows)]
[heightRatios.append(1) for x in range(0,legendRowsNeeded)]
the_grid = GridSpec(totalRows, nCols, height_ratios=heightRatios)
nColors = nAges
cmap = plt.cm.gist_ncar
colors = cmap(np.linspace(0.,1.,nColors))

fig = plt.figure(facecolor='white')
ax = fig.gca()

iCounter = 0
speciesCounter = 0
iRow = totalRows - legendRowsNeeded

for iParent, parent in enumerate(ageNames):
    childrenIdx = parentDict[parent]
    for jChild, child in enumerate(childrenIdx):
        speciesCounter += 1
        spName = ageNames[child]
        plt.subplot(the_grid[jChild,iParent], aspect=1)
        if jChild == 0:
            plt.text(-1, 1.2, parent[0:9]+'.', fontsize=10)
        sliceSize = confMat[child,]
        if confMat[child, child] == 100:
            predictedSlices = plt.pie([100],
                            colors = colors[[child,]],
                            shadow=False,
                            startangle=90,
                            radius=1)
        else:
            predictedSlices = plt.pie(sliceSize,  # data
                colors=colors,  # array of colours
                shadow=False,   # disable shadow
                startangle=90,  # starting angle
                radius=1)
        for wedge in predictedSlices[0]:
            wedge.set_linewidth(0.1)

        actualSlices = plt.pie([100],
                colors=colors[[child,]],
                shadow=False,
                startangle=90,
                radius=0.4)

Abv = parent[0]
        AbvName = Abv + '. ' + spName

        # check if color is dark
        totalColor = 0.299 * colors[child, 0] + 0.587 * colors[child, 1] + 0.114 * colors[child, 2]
        if totalColor > 0.3:
            plt.text(-0.2, -0.1, AbvName[0]+AbvName[3], color='black', fontsize=10)
        else:
            plt.text(-0.2, -0.1, AbvName[0] + AbvName[3], color='white', fontsize=10)

        # draw legend
        if iCounter > nCols-1:
            iCounter = 1
            iRow += 1
        plt.subplot(the_grid[iRow, iCounter], aspect = 2)

        legendDots = plt.pie([100],
                               colors=colors[[child, ]],
                               shadow=False,
                               startangle=90,
                               radius=0.8)

        plt.text(1.2,-0.1,AbvName, fontsize=10) ### 4.5 adjust depending on resolution
        iCounter += 0

mng = plt.get_current_fig_manager()

if you need further clarification or code please let me know! please note I have left some of the wording from the original code (such as parent etc) in the code for loops just for ease, but the relevant parts have been changed.

Screenshot 2019-08-16 at 11 53 36

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.