# PyPlot not working properly

**URL:** https://discourse.julialang.org/t/pyplot-not-working-properly/7060
**Category:** General Usage
**Tags:** question
**Created:** [November 14, 2017, 5:50am UTC](https://discourse.julialang.org/t/pyplot-not-working-properly/7060 "2017-11-14T05:50:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)
#### Post date: [November 14, 2017, 5:50am UTC](https://discourse.julialang.org/t/pyplot-not-working-properly/7060/1 "2017-11-14T05:50:58Z")

</div>

I am using Julia 0.6.0 in Atom and I have installed Plots.jl and PyPlot.jl, so I tried the codes below:

```julia
function fn1(x)                
  y = (x-1.1)^2 - 0.5                
  return y
end

x = collect(-3:6/99:6) 

plot(x,fn1.(x),color=:red,linewidth=2,label="fn1()")
plot!(x,cos.(x),color=:blue,line=(:dash),label="cos")
title!("My Results")
xlabel!("x")
ylabel!("my output value")

```

I got the error message:

```julia
PyError (ccall(@pysym(:PyImport_ImportModule), PyPtr, (Cstring,), name)

The Python package mpl_toolkits.mplot3d could not be found by pyimport. Usually this means
that you did not install mpl_toolkits.mplot3d in the Python version being used by PyCall.

PyCall is currently configured to use the Julia-specific Python distribution
installed by the Conda.jl package. To install the mpl_toolkits.mplot3d module, you can
use `pyimport_conda("mpl_toolkits.mplot3d", PKG)`, where PKG is the Anaconda
package the contains the module mpl_toolkits.mplot3d, or alternatively you can use the
Conda package directly (via `using Conda` followed by `Conda.add` etcetera).

Alternatively, if you want to use a different Python distribution on your
system, such as a system-wide Python (as opposed to the Julia-specific Python),
you can re-configure PyCall with that Python. As explained in the PyCall
documentation, set ENV["PYTHON"] to the path/name of the python executable
you want to use, run Pkg.build("PyCall"), and re-launch Julia.

) <type 'exceptions.ImportError'>
ImportError("/usr/bin/../lib64/../lib64/libz.so.1: version `ZLIB_1.2.9' not found (required by /home/Yifan/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/../../.././libpng16.so.16)",)
  File "/home/Yifan/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/mpl_toolkits/mplot3d/ __init__.py", line 6, in <module>
    from .axes3d import Axes3D
  File "/home/Yifan/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 24, in <module>
    import matplotlib.axes as maxes
  File "/home/Yifan/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/axes/ __init__.py", line 4, in <module>
    from ._subplots import *
  File "/home/Yifan/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/axes/_subplots.py", line 10, in <module>
    from matplotlib.axes._axes import Axes
  File "/home/Yifan/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 22, in <module>
    import matplotlib.contour as mcontour
  File "/home/Yifan/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/contour.py", line 21, in <module>
    import matplotlib.font_manager as font_manager
  File "/home/Yifan/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/font_manager.py", line 58, in <module>
    from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir

pyerr_check at exception.jl:56 [inlined]
pyerr_check at exception.jl:61 [inlined]
macro expansion at exception.jl:81 [inlined]
pyimport(::String) at PyCall.jl:399
_initialize_backend(::Plots.PyPlotBackend) at pyplot.jl:68
backend() at backends.jl:185
Plots.Plot() at types.jl:81
#plot#145(::Array{Any,1}, ::Function, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at plot.jl:54
(::RecipesBase.#kw##plot)(::Array{Any,1}, ::RecipesBase.#plot, ::Array{Float64,1}, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at <missing>:0
(::Atom.##63#66)() at eval.jl:104
withpath(::Atom.##63#66, ::Void) at utils.jl:30
withpath(::Function, ::Void) at eval.jl:38
macro expansion at eval.jl:103 [inlined]
(::Atom.##62#65{Dict{String,Any}})() at task.jl:80

```

---

<div class="post-metadata">

### Author: ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)
#### Post date: [November 14, 2017, 5:57am UTC](https://discourse.julialang.org/t/pyplot-not-working-properly/7060/2 "2017-11-14T05:57:05Z")

</div>

Does calling

```julia
LD_PRELOAD=${HOME}/.julia/v0.6/Conda/deps/usr/lib/libz.so julia

```

as indicated in [https://github.com/JuliaPy/PyPlot.jl/issues/151#issuecomment-287226101](https://github.com/JuliaPy/PyPlot.jl/issues/151#issuecomment-287226101) work for you?

---

<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: [November 14, 2017, 6:58am UTC](https://discourse.julialang.org/t/pyplot-not-working-properly/7060/3 "2017-11-14T06:58:12Z")

</div>

This is an aside, but this code:

> [@Yifan\_Liu](#):
>
> function fn1(x)  
> y = (x-1.1)^2 - 0.5  
> return y  
> end
> 
> x = collect(-3:6/99:6)
> 
> plot(x,fn1.(x),color=:red,linewidth=2,label=“fn1()”)

can be written more succinctly as

```julia
plot(x->(x-1.1)^2-0.5, -3, 6, color=:red,linewidth=2,label=“fn1()”)

```
