Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting is broken #72

Closed
kuanb opened this issue Apr 25, 2017 · 1 comment
Closed

Plotting is broken #72

kuanb opened this issue Apr 25, 2017 · 1 comment

Comments

@kuanb
Copy link
Member

kuanb commented Apr 25, 2017

Likely related to the observation in prev. Issue #71 regarding warnings.

Attempting to plot with Pandana's built in tool results in a blank graph, like this:
image
Above image is based off a bounding box bbox = (-89.566399, 42.984056, -89.229584, 43.171917) (note shown arrangement is before bbox is resorted/ordered in function.

The plot function in UrbanAccess's plot.py file was used in my case as a rough guide to generate a temporary replacement function to enable the plot function in Pandana to work.

Should it be of any assistance, I will include it below:

import matplotlib.pyplot as plt
import matplotlib.cm as cm
from matplotlib import collections as mc
x_min, y_min, x_max, y_max = bbox
bbox_aspect_ratio = (y_max-y_min)/(x_max-x_min)
fig_height = 35
fig, ax = plt.subplots(figsize=(fig_height / bbox_aspect_ratio, fig_height))
x_vals = list(p_net.nodes_df.x.values)
y_vals = list(p_net.nodes_df.y.values)

s = p_net.aggregate(15, type="sum", decay="linear", name="emp")
s = s[s.values == 0]
s[s.values == 0] = 9000

# drop all 0s
data = s[s.values > 0]

num_bins = 10
categories = pd.qcut(x=data, q=num_bins, labels=range(num_bins))
import matplotlib.cm as cm
color_list = [cm.get_cmap('hot')(x) for x in np.linspace(0.1, 0.9, num_bins)]
cleaned_categories = [int(cat) for cat in categories]
colors = [color_list[cat] for cat in cleaned_categories]

ax.scatter(x_vals, y_vals, s=5, c=colors, alpha=0.35, edgecolor='none', zorder=3)

margin=0.02
margin_ns = (y_min-y_max) * margin
margin_ew = (x_min-x_max) * margin
ax.set_ylim((y_min - margin_ns, y_max + margin_ns))
ax.set_xlim((x_min - margin_ew, x_max + margin_ew))

# configure axis
ax.get_xaxis().get_major_formatter().set_useOffset(False)
ax.get_yaxis().get_major_formatter().set_useOffset(False)
ax.axis('off')

plt.savefig('testplot.png', facecolor='black')
@kuanb
Copy link
Member Author

kuanb commented May 5, 2017

Closing this out as plotting error was on my end as Urban Access and Pandana use different bounding box formats.

@kuanb kuanb closed this as completed May 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant