Fix Python – How can I make a scatter plot colored by density in matplotlib?

I’d like to make a scatter plot where each point is colored by the spatial density of nearby points.
I’ve come across a very similar question, which shows an example of this using R:
R Scatter Plot: symbol color represents number of overlapping points
What’s the best way to accomplish something similar in python using matplotlib?
….

Fix Python – How do you send a HEAD HTTP request in Python 2?

What I’m trying to do here is get the headers of a given URL so I can determine the MIME type. I want to be able to see if http://somedomain/foo/ will return an HTML document or a JPEG image for example. Thus, I need to figure out how to send a HEAD request so that I can read the MIME type without having to download the content. Does anyone know o….

Fix Python – How to properly use the “choices” field option in Django

I’m reading the tutorial here: https://docs.djangoproject.com/en/1.5/ref/models/fields/#choices
and i’m trying to create a box where the user can select the month he was born in. What I tried was
MONTH_CHOICES = (
(JANUARY, “January”),
(FEBRUARY, “February”),
(MARCH, “March”),
….
(DECEMBER, “December”),
)

month = CharField(….

Fix Python – What is this odd colon behavior doing?

I am using Python 3.6.1, and I have come across something very strange. I had a simple dictionary assignment typo that took me a long time to find.
context = {}
context[“a”]: 2
print(context)

Output
{}

What is the code context[“a”]: 2 doing? It doesn’t raise a SyntaxError when it should IMO. At first I thought it was creating a slice. However, t….

Fix Python – What’s the difference between ContentType and MimeType?

As far as I know, they are absolute equal. However, browsing some django docs, I’ve
found this piece of code:
HttpResponse.__init__(content=”, mimetype=None, status=200, content_type=’text/html’)
which surprise me the two getting along each other. The official docs was able to solve the issue in a practical manner:

content_type is an alias for m….

Fix Python – What are variable annotations?

Python 3.6 is about to be released. PEP 494 — Python 3.6 Release Schedule mentions the end of December, so I went through What’s New in Python 3.6 to see they mention the variable annotations:

PEP 484 introduced standard for type annotations of function parameters, a.k.a. type hints. This PEP adds syntax to Python for annotating the types of var….

Fix Python – If range() is a generator in Python 3.3, why can I not call next() on a range?

Perhaps I’ve fallen victim to misinformation on the web, but I think it’s more likely just that I’ve misunderstood something. Based on what I’ve learned so far, range() is a generator, and generators can be used as iterators. However, this code:
myrange = range(10)
print(next(myrange))

gives me this error:
TypeError: ‘range’ object is not an it….