# Why does plot use floats on X-axis when an Int16\[\] was supplied?

**URL:** <https://discourse.julialang.org/t/why-does-plot-use-floats-on-x-axis-when-an-int16-was-supplied/6132>\
**Category:** Visualization\
**Created:** [September 28, 2017, 8:23am UTC](https://discourse.julialang.org/t/why-does-plot-use-floats-on-x-axis-when-an-int16-was-supplied/6132 "2017-09-28T08:23:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johann.spies](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johann.spies/32/8805_2.png) [@johann.spies](https://discourse.julialang.org/u/johann.spies)\
**Post date:** [September 28, 2017, 8:23am UTC](https://discourse.julialang.org/t/why-does-plot-use-floats-on-x-axis-when-an-int16-was-supplied/6132/1 "2017-09-28T08:23:14Z")

</div>

I am trying to find my feet in Julia and Plotting.

When I plot df (see below) the xticks shows values like

```julia
2005.0 2007.5 2010.0 2012.5 2015.0

```

while the range is of the type Int16.

I could, after several hours of reading, not find a way how to change that to

```julia
2005 2007 2009 2011 2013 2015

```

By the way is there a better way to convert :pubyear to an array of integers than I have done?

```julia
function pyint(x::Array{Any,1})
    # convert array to Int16
    y = Int16[]
    for i in x
        push!(y, convert(Int16, i))
    end
    y
end

function plot_world_share(df)
    x = pyint(df[:pubyear])
    @df df plot(x, [:Biological_Sciences :Chemistry :Geological_Sciences :Computer_Science :Mathematics :Physics :Statistics])
    end

df = get_world_share() #Not shown here
df[:pubyear]
11-element Array{Any,1}: # [2005:2015]

```

Regards  
Johann

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [September 28, 2017, 8:31am UTC](https://discourse.julialang.org/t/why-does-plot-use-floats-on-x-axis-when-an-int16-was-supplied/6132/2 "2017-09-28T08:31:41Z")

</div>

I don’t know about the plotting but you can do `Int16.(x)` to convert your array.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 28, 2017, 8:38am UTC](https://discourse.julialang.org/t/why-does-plot-use-floats-on-x-axis-when-an-int16-was-supplied/6132/3 "2017-09-28T08:38:22Z")

</div>

Plots converts everything to Float64’s internally. I can see how that can be annoying at times.  
With respect to setting the x ticks you can just

```julia
@df df plot(x, [:Biological_Sciences :Chemistry :Geological_Sciences :Computer_Science :Mathematics :Physics :Statistics], xticks = 2005:2:2015)

```

The best reference for plotting if you want to use the Plots ecosystem (there are several alternatives) is the tables on this page: [https://juliaplots.github.io/attributes/](https://juliaplots.github.io/attributes/)
