Reputation: 1512
I am working on an analysis of tornado data from 1996 to 2015. I am comparing the number of tornadoes to the total property loss by state.
I have a basic plot, but the smaller numbers are bunched too closely together
what I'd like to know is how I can scale this so as to spread these out a bit more?
My code for the plot is
count = tonadoes_1996_damage['count']
loss = tonadoes_1996_damage['total_loss']
max_tornado_count = tonadoes_1996_damage['count'].max()
max_tornado_cnt_label = tonadoes_1996_damage[tonadoes_1996_damage['count'] == max_tornado_count].index.tolist()[0]
max_tornado_cnt_x = tonadoes_1996_damage[tonadoes_1996_damage['count'] == max_tornado_count]['count']
max_tornado_cnt_y = tonadoes_1996_damage[tonadoes_1996_damage['count'] == max_tornado_count]['total_loss']
max_tornado_loss = tonadoes_1996_damage['total_loss'].max()
max_tornado_loss_label = tonadoes_1996_damage[tonadoes_1996_damage['total_loss'] == max_tornado_loss].index.tolist()[0]
max_tornado_loss_x = tonadoes_1996_damage[tonadoes_1996_damage['total_loss'] == max_tornado_loss]['count']
max_tornado_loss_y = tonadoes_1996_damage[tonadoes_1996_damage['total_loss'] == max_tornado_loss]['total_loss']
colors = np.random.rand(51)
area = count
plt.scatter(count, loss,s=area,c=colors,alpha=.5)
xlab = "Number of Tornadoes [in thousands]"
ylab = "Total Loss [in million USD]"
title = "Total Property Loss Since 1996"
plt.xlabel(xlab)
plt.xlim(0, 3500)
plt.ylabel(ylab)
plt.ylim(0, 6000)
plt.title(title)
plt.grid(True)
plt.text(max_tornado_cnt_x, max_tornado_cnt_y, max_tornado_cnt_label)
plt.text(max_tornado_loss_x, max_tornado_loss_y, max_tornado_loss_label)
plt.show()
I've played around with setting the x-ticks and y-ticks but those don't seem to adjust the scale, just add more ticks (unless I am doing something wrong.
Upvotes: 0
Views: 3586
Reputation: 7466
You could use logarithmic scale for the x-axis and this will improve the visualisation: http://matplotlib.org/examples/pylab_examples/log_demo.html
Try something like:
fig = plt.figure(figsize=(11, 8))
ax = fig.add_subplot(1, 1, 1)
ax.set_xscale('log')
plt.scatter(count, loss,s=area,c=colors,alpha=.5)
and then add all properties accordingly.
Upvotes: 1