Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Some error in a try to construct an histogram

This is my own histogram code

def my_histo(l, ll,couleur='skyblue',bord='red',montext="$ABC$",rapport='automatic',ajust=-1225):
    A=sum(plot(polygon([(l[j],0),(l[j],ll[j]),(l[j+1],ll[j]),(l[j+1],0)],color=couleur, 
         edgecolor=bord)) for j in range(len(l)-1))
    T = text(montext,((min(l)+max(l))/2,ajust))
    return show(A+T,aspect_ratio=rapport)

with the following data it works approximatively nicely

y=list([7301.06,  2887.38, 429.70, 1104.18, 773.924, 0.000000, 0.000000, 0.000000,
 0.000000, 0.000000, 1828.35, 1921.33, 0.000000, 0.000000,  0.000000, 0.000000,
 0.000000, 0.000000,0.000000, 3395.03])

and

x = [75.6750, 251.025, 426.375, 601.725, 777.075, 952.425,  1127.78, 1303.12, 1478.48,
 1653.83, 1829.18, 2004.53, 2179.88, 2355.23, 2530.58, 2705.93, 2881.28, 3056.62, 3231.98, 3407.33]

my_histo(x, y, couleur='skyblue',bord='red')

But I have made a mistake since the last value is not displayed as a rectangle and I do not see which. Then the y axis extend under 0 isd there a way to forbid that.

Some error in a try to construct an histogram

This is my own histogram code

def my_histo(l, ll,couleur='skyblue',bord='red',montext="$ABC$",rapport='automatic',ajust=-1225):
    A=sum(plot(polygon([(l[j],0),(l[j],ll[j]),(l[j+1],ll[j]),(l[j+1],0)],color=couleur, 
         edgecolor=bord)) for j in range(len(l)-1))
    T = text(montext,((min(l)+max(l))/2,ajust))
    return show(A+T,aspect_ratio=rapport)

with the following data it works approximatively nicely

y=list([7301.06,  2887.38, 429.70, 1104.18, 773.924, 0.000000, 0.000000, 0.000000,
 0.000000, 0.000000, 1828.35, 1921.33, 0.000000, 0.000000,  0.000000, 0.000000,
 0.000000, 0.000000,0.000000, 3395.03])

and

x = [75.6750, 251.025, 426.375, 601.725, 777.075, 952.425,  1127.78, 1303.12, 1478.48,
 1653.83, 1829.18, 2004.53, 2179.88, 2355.23, 2530.58, 2705.93, 2881.28, 3056.62, 3231.98, 3407.33]

my_histo(x, y, couleur='skyblue',bord='red')

But I have made a mistake since the last value is not displayed as a rectangle and I do not see which. Then the y axis extend under 0 isd is there a way to forbid that. that.

Some error in a try to construct an histogram

This is my own histogram code

def my_histo(l, ll,couleur='skyblue',bord='red',montext="$ABC$",rapport='automatic',ajust=-1225):
    A=sum(plot(polygon([(l[j],0),(l[j],ll[j]),(l[j+1],ll[j]),(l[j+1],0)],color=couleur, 
         edgecolor=bord)) for j in range(len(l)-1))
    T = text(montext,((min(l)+max(l))/2,ajust))
    return show(A+T,aspect_ratio=rapport)

with the following data it works approximatively nicely

y=list([7301.06,  2887.38, 429.70, 1104.18, 773.924, 0.000000, 0.000000, 0.000000,
 0.000000, 0.000000, 1828.35, 1921.33, 0.000000, 0.000000,  0.000000, 0.000000,
 0.000000, 0.000000,0.000000, 3395.03])

and

x = [75.6750, 251.025, 426.375, 601.725, 777.075, 952.425,  1127.78, 1303.12, 1478.48,
 1653.83, 1829.18, 2004.53, 2179.88, 2355.23, 2530.58, 2705.93, 2881.28, 3056.62, 3231.98, 3407.33]

my_histo(x, y, couleur='skyblue',bord='red')

But I have made a mistake since the last value is not displayed as a rectangle and I do not see which. Then the y axis extend under 0 is there a way to forbid that.

Some error in a try to construct an histogram

This is my own histogram code

def my_histo(l, ll,couleur='skyblue',bord='red',montext="$ABC$",rapport='automatic',ajust=-1225):
    A=sum(plot(polygon([(l[j],0),(l[j],ll[j]),(l[j+1],ll[j]),(l[j+1],0)],color=couleur, 
         edgecolor=bord)) for j in range(len(l)-1))
    T = text(montext,((min(l)+max(l))/2,ajust))
    return show(A+T,aspect_ratio=rapport)

with the following data it works approximatively nicely

y=list([7301.06,  2887.38, 429.70, 1104.18, 773.924, 0.000000, 0.000000, 0.000000,
 0.000000, 0.000000, 1828.35, 1921.33, 0.000000, 0.000000,  0.000000, 0.000000,
 0.000000, 0.000000,0.000000, 3395.03])

and

x = [75.6750, 251.025, 426.375, 601.725, 777.075, 952.425,  1127.78, 1303.12, 1478.48,
 1653.83, 1829.18, 2004.53, 2179.88, 2355.23, 2530.58, 2705.93, 2881.28, 3056.62, 3231.98, 3407.33]

my_histo(x, y, couleur='skyblue',bord='red')

But I have made a mistake since the last value is not displayed as a rectangle and I do not see which. Then the y axis extend under 0 is there a way to forbid that.

Some error Error in a try to construct an histogram

This is my own histogram code

def my_histo(l, ll,couleur='skyblue',bord='red',montext="$ABC$",rapport='automatic',ajust=-1225):
    A=sum(plot(polygon([(l[j],0),(l[j],ll[j]),(l[j+1],ll[j]),(l[j+1],0)],color=couleur, 
         edgecolor=bord)) for j in range(len(l)-1))
    T = text(montext,((min(l)+max(l))/2,ajust))
    return show(A+T,aspect_ratio=rapport)

with the following data it works approximatively nicely

y=list([7301.06,  2887.38, 429.70, 1104.18, 773.924, 0.000000, 0.000000, 0.000000,
 0.000000, 0.000000, 1828.35, 1921.33, 0.000000, 0.000000,  0.000000, 0.000000,
 0.000000, 0.000000,0.000000, 3395.03])

and

x = [75.6750, 251.025, 426.375, 601.725, 777.075, 952.425,  1127.78, 1303.12, 1478.48,
 1653.83, 1829.18, 2004.53, 2179.88, 2355.23, 2530.58, 2705.93, 2881.28, 3056.62, 3231.98, 3407.33]

my_histo(x, y, couleur='skyblue',bord='red')

But I have made a mistake since the last value is not displayed as a rectangle and I do not see which. Then the y axis extend under 0 is there a way to forbid that.

Also how to make the x-ticks according to the values ?

Error in an histogram

This is Since I have solved my own histogram codeproblem I give the code and ask how to print only one time the 0 or multiple occurences of a number. Of course it will be possible to remove all the zero of y less one but I would prefer to incorporate this in the function.

def my_histo(l, ll,couleur='skyblue',bord='red',montext="$ABC$",rapport='automatic',ajust=-1225):
ll,couleur='skyblue',bord='red',montext="$ABC$",rapport='automatic',ajust=5000,politail=5):
    A=sum(plot(polygon([(l[j],0),(l[j],ll[j]),(l[j+1],ll[j]),(l[j+1],0)],color=couleur, 
         edgecolor=bord)) for j in range(len(l)-1))
    B=plot(polygon([(l[len(l)-2],0),(l[len(l)-2],ll[len(ll)-1]),(l[len(l)-1],ll[len(ll)-1]),(l[len(l)-1],0)],color=couleur, 
         edgecolor=bord))
    T = text(montext,((min(l)+max(l))/2,ajust))
    return show(A+T,aspect_ratio=rapport)
show(A+B+T,aspect_ratio=rapport,ticks=[l,ll],fontsize=politail) my_histo(list(X), list(Vtc[0]),couleur='skyblue',bord='red')

with the following data it works approximatively nicely

y=list([7301.06,  2887.38, 429.70, 1104.18, 773.924, 0.000000, 0.000000, 0.000000,
 0.000000, 0.000000, 1828.35, 1921.33, 0.000000, 0.000000,  0.000000, 0.000000,
 0.000000, 0.000000,0.000000, 3395.03])

and

x = [75.6750, 251.025, 426.375, 601.725, 777.075, 952.425,  1127.78, 1303.12, 1478.48,
 1653.83, 1829.18, 2004.53, 2179.88, 2355.23, 2530.58, 2705.93, 2881.28, 3056.62, 3231.98, 3407.33]

my_histo(x, y, couleur='skyblue',bord='red')

But I have made a mistake since the last value is not displayed as a rectangle and I do not see which. Then the y axis extend under 0 is there a way to forbid that.

Also how to make the x-ticks according to the values ?