Skip to main content

Data Visualization with Python

Scatter plots with Matplotlib 

I'm in the middle of taking a 6 week Data Visualization course at Code Academy so I guess you might call this a midterm project. In this jupyter notebook project, we have use real world space data (celestial star location ) for the Orion constellation and output a 3D scatter plot. This was fun but because it is an intro course, the project didn't even get to labeling the actual star which I thought was bunk. 

At the end of the project, they offer you a link to some star data and challenge you to plot some local stars. So I decided to publish my results that I will end up turning in for the extra credit portion of the project. (code below)

I picked a few stars, starting with some familiar ones, like Sirius, and started plotting it out. It took a while to get the labels on correctly, for some reason, I thought it was going to be easy but it definitely took some searching as the 3D portion of it made finding the examples far more challenging than the standard 2D graphs.  The output was cool.

However, the coolest thing about a 3D chart is being able to to turn and view it from any angle. I created an animation after another hour or so which was excellent. The final part and by far the most difficult was exporting the animation as a gif/video. That part I did outside of code and just used some other software. The matplotlib needs some help with that since it requires a third party software such as ImageMagik or FFMPEG. 

from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation

# star data from using Celestial (X,Y,Z) coordinates
new_star_legend = ['Procyon', 'Sirius', '61 Cygni','Alpha/Proxima Centari', 'Wolf 359']
a = [ -4.769, -1.612, 6.489, -1.643 ,  -0.0566 ]
b = [10.31, 8.078, -6.109, -1.374,  -5.920]
c = [1.039, -2.474, 7.152, -3.838, 0.486]

# create the figure and subplot axes
fig = plt.figure()
ax = fig.add_subplot(1,1,1,projection='3d')
ax.set_title('Celestial (X,Y,Z) coordinates in ly')

# scatter plot
ax.scatter(a, b, c, marker='*', linewidth=4)

# apply labels to each star
for zdir, x, y, z in zip(new_star_legend, a, b, c):
    ax.text(x, y, z, zdir)

# apply a simple rotation animation
for angle in range(0, 360):
    ax.view_init(30, angle)

# the show method is not needed in this instance



  1. I like your blog, I read this blog please update more content on python, further check it once at python online training


Post a Comment

Popular posts from this blog


Earlier this year I began playing with an open source instagram bot, InstaPy, after hearing the creator talk about web automation with selenium. I was very impressed and frankly amazed with what was possible with selenium and wanted to see how I could incorporate it in both my personal projects and professional career.

Since 2010, I had posted more images on IG than Flickr, 8,200+ with a good chunk of them "throw away" images. I already backed up my photos so now came the challenge to clean/delete my feed. Spring cleaning, pruning the hedges, whatever you want to call it, IG doesn't make it easy.

Enter Insta_Delete (no relation to the app that kept popping up in my google searches).

I decided to build myself a bot glorified script to first scroll as far back as possible on my feed, then scrape the page for URL's, parse and find the href links, save them to a file, log in with a mobile emulated browser and delete those old posts.

I wrote a script that is working now, …

Copy SSIS packages from MS SQL SERVER 2008 R2

Copy SSIS packages from SQL Server 2008 R2 to another SQL Server 2008 First day at the new job I was asked if I knew anything about moving SSIS packages from one server to another server. The developer/dbo was dreading having to manually download and deploy the SSIS packages from the old server to the new server.

I quickly started looking for an automated, scripted solution and came across this stackoverflow post that was asking nearly the exact same question.  The only real difference was the original question was asking about  moving where as we needed to copy. (moving meant removing from old server as we nearly found out the hard way).

Below is the sql code from that post that I decided to group together on my github for sharing and for later use which by the way, I ended up reusing. I think making this into a stored procedure with a few more bells and whistles might come in handy. 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 3…