Skip to content

Instantly share code, notes, and snippets.

@ararog ararog/plot1.jl
Last active Nov 26, 2015

What would you like to do?
Sample code that ilustrastes how plotting is done with Julia programming language.
# Installing and loading libraries if needed
using Gadfly
using DataFrames
using DataFramesMeta
using ZipFile
using HTTPClient.HTTPC
# Read computer available memory
#available_memory = memory.limit()
# Since this information has been provided in advance,
# I choose to not perform any extra work to guess them
number_of_rows = 2075259
number_of_cols = 9
bytes_per_cell = 8
data_size_bytes = number_of_rows * number_of_cols * bytes_per_cell
data_size_mb = data_size_bytes / (1024 ^ 2)
println("Checking if there's enough memory available")
#if data_size_mb > available_memory
# println("There's no available memory to load dataset required to run this script, exiting...")
# exit()
if ! isfile("")
println("Downloading dataset archive...")
HTTPC.get("", RequestOptions(ostream=""))
println("Dataset archive already downloaded, continuing")
if isfile("")
if ! isfile("household_power_consumption.txt")
println("Unzipping dataset archive")
r = ZipFile.Reader("");
for f in r.files
file = open(,"w")
write(file, readall(f))
println("Checking if household_power_consumption.txt exists...")
if isfile("household_power_consumption.txt")
classes = [UTF8String, UTF8String, Float64,
Float64, Float64, Float64, Float64, Float64, Float64]
println("Loading data")
eletricPowerData = readtable("household_power_consumption.txt",
separator = ';', header=true, eltypes = classes, nastrings = ["", "NA", "?"])
eletricPowerData_subset = @where(eletricPowerData, (:Date .== "1/2/2007") | (:Date .== "2/2/2007"))
println("Plotting data and saving the image to disk")
p = plot(eletricPowerData_subset, x="Global_active_power", Geom.histogram,
Guide.ylabel("Frequency"), Guide.xlabel("Global Active Power (kilowatts)"), Guide.title("Global Active Power"))
draw(PNG("plot1.png", 6inch, 3inch), p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.