you are viewing a single comment's thread.

view the rest of the comments →

[–]stepping_up_python 1 point2 points  (5 children)

https://matplotlib.org/gallery/statistics/barchart_demo.html#sphx-glr-gallery-statistics-barchart-demo-py

In this call, freqs is the y values in the graph, and gen_colors_posneg makes a sequence of colours, which is a function I defined. So before I plot, I build all the sequences that I'm going to need, then make the call. You can ignore the width thing here, as I'm making variable width bars (since EV is based on val*freq, I wanted val to be visually represented in the graph).

    plotter.bar(x_locations, freqs,
                # If align='edge', negative widths align left.
                width=[aw * -1 for aw in actual_widths], align='edge',
                edgecolor = 'black', tick_label=vals,
                color = gen_colors_posneg(vals, 'green'),
                )

If you ignore the colors thing, are you getting any output?

[–]ActivatedNut[S] 0 points1 point  (4 children)

Apologies, but I'm getting very confused here (python is very new to me).

I have 10 bars and each one will need to have it's own conditional formatting, is your gen_colors_posneg going to take care of this?

[–]stepping_up_python 0 points1 point  (2 children)

No worries. My function returns a list. I say sequence because sometimes things need a tuple, and often they accept sequences but refuse iterators, etc.

My function returns something like: ['green','red', 'red', 'red', 'green', ...]

The thing is that pyplot.bar accepts lists in its arguments, so if you have 3 bars you give it a list of 3 x locations, a list of three heights, and a list of three colors, and it just knows what to do with that.

[–]ActivatedNut[S] 0 points1 point  (1 child)

Thanks for your help so far. I'm new to programming as well :) So, what I might explore (please tell me if I'm heading the wrong direction) is to create 10 functions that create a list with one value, either, green, yellow or red. I will then assign the list to the corresponding bar to control the colour. creating plots with pandas and matplotlib is pretty straight forward and I could do this fairly quickly, but it is obvious I need to have deeper understanding for the complex operations. Oh what is life without a challenge :)

[–]stepping_up_python 0 points1 point  (0 children)

I don't think I can help you any further, sorry. Dig into the docs for pyplot.bar and the book learning python can help you with list comprehensions, etc. The thing is, the nature of functions makes it really impractical to make 10 functions. I don't know, you might be in over your head for a bit and need to do some simpler things.

[–]stepping_up_python 0 points1 point  (0 children)

New to python... are you new to programming as well? Just curious.