I have some code that expresses the balance of an election result in the form of a violin plot:
plt.plot((0, 0), (0.85, 1.15), 'k-')
p = plt.violinplot(np.array(results['Balance']),vert=False, bw_method='scott', widths=0.2,showextrema=False)
This returns a plot that looks like the following:
I would like to colour this plot either side of the "Decision Line" to reflect voting intention. Something like the mock-up shown below:
I've tried plotting the two distinct sets independently of one another, e.g.
p = plt.violinplot(np.array(results[results['Balance']>=0]['Balance']),vert=False, bw_method='scott', widths=0.2,showextrema=False)
n = plt.violinplot(np.array(results[results['Balance']<0]['Balance']),vert=False, bw_method='scott', widths=0.2,showextrema=False)
I might then use the method discussed here to colour each PolyCollection
differently.
But the shape returned no longer reflects the original distribution, and so is too far from what I'm looking for to be helpful in this instance.
Does anyone have any ideas or techniques for achieving something closer to my coloured mockup?