1

I am more or less a hobby programmer and found that python and matplotlib create some nice outputs. I am attempting to analyze a comma separated output and display data. I was able to get my data from the text file into sqlite3 and I use sqlite3 to perform some sums and sorting, but then the output has a box in it. my output has flexible data

{so I do not know how many columns I have, so I found by trial and error that if I predefine colors that it will just repeat them. not really relevant}

the data is for example:

Error1, 10000 Error2, 5000 Error3, 4000 Error4, 3000

I am almost there, I have a tiny little white box (almost like a check box) in my legend where I display Error1..Error4 that I cannot figure out where it is coming from.

I tried Moving matplotlib legend outside of the axis makes it cutoff by the figure box, but it did not work for me. I guess I really should not be doing this as I do not exactly know what I am doing...

import numpy as np
import pylab as pl
import sqlite3

values = []
strlegend = []

db_filename = 'test.sqlite'

conn = sqlite3.connect(db_filename)
cursor = conn.cursor()

sql1 = "select  detailcat, sum(duration) from jmfdata where submaincat = 'Down' and detailCat <> '\N' group by detailcat order by sum(duration) desc"
cursor.execute(sql1)
fracs = cursor.fetchall()

for lines in fracs:
    values.append(lines[1])
    strlegend.append(lines[0])

colors = ('red','pink','orange', 'yellow', 'yellowgreen', 'green','teal','aliceblue','blue','purple')

fig = pl.figure(2, figsize=(11,11))
ax = pl.subplot(111)
width=0.8
pl.title('Down Code Reasons')
ax.bar(range(len(strlegend)), values, width=width,color = colors)
ax.set_xticks(np.arange(len(strlegend)) + width/2)
ax.set_xticklabels(strlegend, rotation=75)
handles, labels = ax.get_legend_handles_labels()
lgd = ax.legend(handles, labels, loc='upper center', bbox_to_anchor=(0.5,-0.1))
fig.savefig('samplefigure03.pdf', bbox_extra_artists=(lgd,), bbox_inches='tight')
Community
  • 1
  • 1
user2565278
  • 77
  • 1
  • 7

0 Answers0