# How to plot from a CSV file?

**URL:** <https://discourse.julialang.org/t/how-to-plot-from-a-csv-file/9508>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [March 5, 2018, 1:41pm UTC](https://discourse.julialang.org/t/how-to-plot-from-a-csv-file/9508 "2018-03-05T13:41:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![etairi](https://avatars.discourse-cdn.com/v4/letter/e/c89c15/32.png) [@etairi](https://discourse.julialang.org/u/etairi)\
**Post date:** [March 5, 2018, 1:41pm UTC](https://discourse.julialang.org/t/how-to-plot-from-a-csv-file/9508/1 "2018-03-05T13:41:28Z")

</div>

I have the following Julia code:

```julia
using DataFrames, CSV
using Cairo, Gadfly

data = CSV.read("simulate_public.csv")
p = plot(data, x=:p, y=:Expected, Geom.point);
img = SVG("public_plot.svg", 6inch, 4inch)
draw(img, p)

```

Now, my CSV file (and also the data variable here), have six columns, and they are` eA`, `eB`, `f` , `p`, `Expected`, `Simulated`. But, what’s important for me are the last three columns, namely `p`, `Expected` and `Simulated`. According to the printed values in Julia notebook, it says that `p` has type of `Nullable{Int64}`, `Expected` and `Simulated` have types of `Nullable{Float64}`. So, what I want to plot is that, I want the x-axis to be values of `p`, and in y-axis I want to have the values for `Expected` and `Simulated`. Though, I do not know how to combine two plots in one. Also, I want `Expected` to be plotted as unfilled blue points (circles), and `Simulated` to be plotted as red crosses (x), So basically I want to see whether the `Expected` values match the `Simulated` values that I have. So, one problem is that I do not know how to combine two different sets of data in the same plot, and when I also run the above code I get the following error message:

> MethodError: no method matching isfinite(::Nullable{Float64})

Any ideas how to achieve what I want in Julia?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [March 5, 2018, 1:42pm UTC](https://discourse.julialang.org/t/how-to-plot-from-a-csv-file/9508/2 "2018-03-05T13:42:52Z")

</div>

You are probably using an outdated version of the CSV package. Use `readtable` instead of `CSV.read`, or try to identify the installed package which prevents you from updating DataFrames and CSV to their latest versions (see [How to upgrade from DataFrames 0.10.1 to 0.11.3?](https://discourse.julialang.org/t/how-to-upgrade-from-dataframes-0-10-1-to-0-11-3/8243/)).

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [March 5, 2018, 5:56pm UTC](https://discourse.julialang.org/t/how-to-plot-from-a-csv-file/9508/3 "2018-03-05T17:56:15Z")

</div>

- `CSV` with `Gadfly`: use `CSV.read(..., nullable=false)`. More info [here](https://github.com/GiovineItalia/Gadfly.jl/issues/1083#issuecomment-354912987)
- For your other questions, see the `Gadfly` docs e.g. [`Geom.point`](http://gadflyjl.org/stable/lib/geoms/geom_point.html), [`Shapes`](http://gadflyjl.org/stable/lib/shapes.html)

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [March 5, 2018, 6:21pm UTC](https://discourse.julialang.org/t/how-to-plot-from-a-csv-file/9508/4 "2018-03-05T18:21:08Z")

</div>

If you are stuck on an old DataFrames/CSV combo because you need some other package that prevents them from updating, you can also try [CSVFiles.jl](https://github.com/davidanthoff/CSVFiles.jl):

```julia
using CSVFiles, FileIO, Gadfly

p = plot(load("simulate_public.csv"), x=:p, y=:Expected, Geom.point)

```

Note that `load(filename)` doesn’t return a `DataFrame`, but because of the iterable tables integration for both CSVFiles and Gadfly things should still just work (i.e. the data is transferred directly from the load to the plot function).

If I got all this complicated logic right, this should work regardless of what version of DataFrames/Gadfly you are using.

---

<div class="post-metadata">

**Author:** ![etairi](https://avatars.discourse-cdn.com/v4/letter/e/c89c15/32.png) [@etairi](https://discourse.julialang.org/u/etairi)\
**Post date:** [March 5, 2018, 10:49pm UTC](https://discourse.julialang.org/t/how-to-plot-from-a-csv-file/9508/5 "2018-03-05T22:49:13Z")

</div>

Thanks, `readtable` solved it.
