Sane color scheme for Matplotlib

6 comments    Posted on February 8th, 2011

What Python’s MatPlotlib allows for in flexibility, it majorly lacks in aesthetics. Compared to graphs produced using ggplot2, the graphs I make using matplotlib strain my eyes. For the most part, this is caused by its default color scheme which the creator, John Hunter, optimized for display in publications rather than the web.

I spent some time over the weekend to refine the default colors and settings for my matplotlib installation. The result of this work is embodied in this .matplotlibrc color theme file. If you want graphs that look like the ones below by default, download it and place the file under ~/.matplotlib/matplotlibrc.







Under the hood: An HTTP request with multipart/form-data

2 comments    Posted on February 6th, 2011

Check yourself, do you know what an HTTP request looks like coming over the wire? No, not the raw bits or the flowing electrons. Just try to picture the actual HTTP request body as text. Now imagine what it looks like if the HTTP request has an image attached. Here it is. This is what the internet is built on.

/
User-Agent: curl/7.21.2 (x86_64-apple-darwin)
Host: localhost:8080
Accept: */*
Content-Length: 1143
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------83ff53821b7c

------------------------------83ff53821b7c
Content-Disposition: form-data; name="img"; filename="a.png"
Content-Type: application/octet-stream

?PNG

IHD?wS??iCCPICC Profilex?T?kA?6n??Zk?x?"IY?hE?6?bk
Y?<ߡ)??????9Nyx?+=?Y"|@5-?M?S?%?@?H8??qR>?׋??inf???O?????b??N?????~N??>?!?
??V?J?p?8?da?sZHO?Ln?}&???wVQ?y?g????E??0
 ??
   IDAc????????-IEND?B`?
------------------------------83ff53821b7c
Content-Disposition: form-data; name="foo"

bar
------------------------------83ff53821b7c--

You don’t always need to know what’s under the hood. But sometimes, it’s just magical to realize that the thing you’re using everyday is nothing more than this. What other protocols do you take for granted yet find completely amazing?

To watch raw HTTP requests yourself

  1. Get reflect.py — an echo server for HTTP requests
  2. Run this in terminal #1 python reflect.py
  3. Run this in terminal #2 curl -X POST -F foo=bar -F img=@a.png localhost:8080