# Bar chart of capitals by latitude in 5 degree increments in the lower left of the figure

by Brianna   Last Updated April 16, 2019 00:22 AM

Trying to figure out how to plot a bar graph with my lat and long data (minus Alaska and Hawaii)... The bar graph also needs to be in 5 degree increments.

Here is my code so far for the 3 part image... I'm new at python so bear with me. from matplotlib import pyplot as plt import numpy as np import geopandas as gp import TopherInOut import StateGeomFuncs import capitalguessFUNC

# figure size. shows what each section size should be

plt.figure(figsize=(8, 6), dpi=90)

# lat and count are just varibles, could be anything

Lat=[10,20,30] Count=[3, 9, 2]

# labels the x axis subheadings

plt.xticks([10,20,30],['10-20','20-30','30-40'], fontsize=10)

# labels the x axis

plt.xlabel('Latitudes')

# labels the y axis subheadings

plt.yticks([10,20,30],['10-20','20-30','30-40'], fontsize=10)

# labels the y axis subheading

plt.ylabel('Count')

gridsize=(3,2)

# its going to plot across 2 rows and 2 columns, but ONLY plot where it intersects

ax1 = plt.subplot2grid(gridsize, (0, 0), colspan=2, rowspan=2)

# lower left labeling

ax2 = plt.subplot2grid(gridsize, (2, 0))

# lower right labeling

ax3 = plt.subplot2grid(gridsize, (2, 1))

# LatLongVariable=capitalguessFUNC.initial_list()

#creating a scatter plot and calling in the data #however, it isnt plotting for some reason?????????????????????????

# labeling axis number two as a bar graph

ax2.bar(Lat, Count, width=9.0)

# set the x tick marks to 10 20 30

ax2.set_xticks([10,20,30])

# labels x

ax2.set_xticklabels(['10-20','20-30','30-40'])

# labels the y axis and font size

ax2.set_yticklabels(['0','5', '10', '15', '20'],fontsize=7)

# labeling axis number three as a bar graph

ax3.bar(Lat, Count, width=9.0)

# set the x tick marks to 10 20 30

ax3.set_xticks([10,20,30])

# labels x

ax3.set_xticklabels(['10-20','20-30','30-40'])

# labels the y axis and font size

ax3.set_yticklabels(['0','5', '10', '15', '20'],fontsize=7)

# places the title above axis 1

ax1.set(title='Continguous States')

CapLat=[40.27, 32.3615, 58.301935, 33.448457, 34.736009, 38.555605, 39.7391667,41.767,39.161921, 30.4518, 33.76,21.30895, 43.613739, 39.783250, 39.790942, 41.590939, 39.04, 38.197274, 30.45809, 44.323535, 38.972945, 42.2352, 42.7335, 44.95, 32.320 , 38.572954, 46.595805, 40.809868, 39.160949,43.220093, 40.221741, 35.667231, 42.659829, 35.771, 48.813343, 39.962245, 35.482309, 44.931109, 40.269789, 41.82355, 34.000, 44.367966, 36.165, 30.266667, 40.7547, 44.26639, 37.54, 47.042418, 38.349497, 43.074722, 33.448457] CapLon=[-76.89, -86.279118, -134.419740, -112.073844,-92.331122, -121.468926, -104.984167,-72.677, -75.526755, -84.27277, -84.39, -157.826182, -116.237651, -89.650373, -86.147685, -93.620866, -95.69, -84.86311, -91.140229, -69.765261, -76.501157, -71.0275, -84.5467, -93.094, -90.207, -92.189283, -96.675345, -119.753877, -71.549127, -74.756138, -105.964575,-73.781339, -78.638, -100.779004, -83.000647, -97.534994, -123.029159, -76.875613, -71.422132, -81.035, -100.336378, -86.784, -97.75, -111.892622,-72.57194, -77.46, -122.893077, -81.633294, -89.384444, -112.073844]

# plot the map data

contigstates.plot(ax=ax1)

ax1.scatter(CapLon, CapLat, marker="*", color='gold', label="Capitals")

# lat is the x axis

Lat=[10,20,30] Count=[3,9,2]

# legend and location

ax1.legend(loc='upper left') ax2.legend(loc='upper left')
ax3.legend(loc='upper left')

Tags :

## Related Questions

Updated April 30, 2018 22:22 PM

Updated May 24, 2018 20:22 PM

Updated June 19, 2018 21:22 PM

Updated August 31, 2018 18:22 PM

Updated July 03, 2019 10:22 AM