On Thu, Jun 21, 2012 at 6:42 PM, Alan G Isaac <alan.is...@gmail.com> wrote:

> I never thought it would happen, but the
> Matplotlib Gallery has for once failed me:
> http://matplotlib.sourceforge.net/gallery.html
>
> I was looking for an example of creating a nice
> tornado chart:
>
> http://code.enthought.com/projects/chaco/docs/html/user_manual/tutorial_1.html
> http://www.tushar-mehta.com/excel/software/tornado/
> http://www.juiceanalytics.com/writing/recreating-ny-times-cancer-graph/
>
> A basic version will do, say along the lines of
> the Chaco example.
>
> Thanks for any leads,
> Alan Isaac
>
>
Hi Alan,

Here's an example based off the horizontal bar charts in the gallery. There
may be a better way to align the y-tick labels (the example manually tweaks
the x-offset), but I don't know how to do it off the top of my head.
Alternatively, you could put the ticks on the left and squish the space
between subplots (using `subplots_adjust(wspace=0)` but then you run into
the issue of overlapping x-tick labels.

Hope that helps,
-Tony

# tornado chart example
import numpy as np
import matplotlib.pyplot as plt


people = ('Tom', 'Dick', 'Harry', 'Slim', 'Jim')
num_people = len(people)

time_spent = np.random.uniform(low=5, high=100, size=num_people)
proficiency = np.abs(time_spent / 12. + np.random.normal(size=num_people))
pos = np.arange(num_people) + .5    # bars centered on the y axis

fig, (ax_left, ax_right) = plt.subplots(ncols=2)
ax_left.barh(pos, time_spent, align='center', facecolor='cornflowerblue')
ax_left.set_yticks([])
ax_left.set_xlabel('Hours spent')
ax_left.invert_xaxis()

ax_right.barh(pos, proficiency, align='center', facecolor='lemonchiffon')
ax_right.set_yticks(pos)
# x moves tick labels relative to left edge of axes in axes units
ax_right.set_yticklabels(people, ha='center', x=-0.08)
ax_right.set_xlabel('Proficiency')

plt.suptitle('Learning Python')

plt.show()
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to