Learning the Pandas Library: Python Tools for Data Munging, Analysis, and Visualization (Treading on Python Book 3) by Matt Harrison

Learning the Pandas Library: Python Tools for Data Munging, Analysis, and Visualization (Treading on Python Book 3) by Matt Harrison

Author:Matt Harrison [Harrison, Matt]
Language: eng
Format: epub, pdf
Tags: Python Programming Language
Publisher: Matt Harrison
Published: 2016-06-06T21:00:00+00:00


Plot using secondary_y parameter to use different scales on the left and right axis for elevation and distance.

Another way to convey information is to plot with labels along the x axis instead of using a numerical index (which does not mean much to viewers of the graph). By default, pandas plots the index along the x axis. To graph against the name of the station, we need to pass in an explicit value for x, the ELEVATION column. The labels will need to tilted a bit so that they do not overlap. This rotation is done with fig.autofmt_xdate(). The bounding box also needs to be expanded a bit so the labels do not get clipped off at the edges. The bbox_inches='tight' parameter to fig.savefig will help with this:

>>> fig = plt.figure() >>> ax = fig.add_subplot(111) >>> df.plot(x='LOCATION', y=['ELEVATION', 'CUMUL'], ax=ax) >>> df.plot(x='LOCATION', y='MILES', secondary_y=True, ax=ax) >>> ax.set_ylabel('Elevation (feet)') >>> ax.right_ax.set_ylabel('Distance (miles)') >>> fig.autofmt_xdate() >>> fig.savefig('/tmp/df-ex4.png', bbox_inches='tight')



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.