All Projects → MaxStrange → expyplot

MaxStrange / expyplot

Licence: MIT license
Matplotlib for Elixir

Programming Languages

elixir
2628 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to expyplot

Pyplot.jl
Plotting for Julia based on matplotlib.pyplot
Stars: ✭ 347 (+1185.19%)
Mutual labels:  matplotlib, plotting
planetMagFields
Routines to plot magnetic fields of planets in our solar system
Stars: ✭ 27 (+0%)
Mutual labels:  matplotlib, plotting
Chartpy
Easy to use Python API wrapper to plot charts with matplotlib, plotly, bokeh and more
Stars: ✭ 426 (+1477.78%)
Mutual labels:  matplotlib, plotting
Matplotlib Venn
Area-weighted venn-diagrams for Python/matplotlib
Stars: ✭ 260 (+862.96%)
Mutual labels:  matplotlib, plotting
2021-bordeaux-dataviz
Scientific Visualization Crash Course (Python & Matplotlib)
Stars: ✭ 20 (-25.93%)
Mutual labels:  matplotlib, plotting
Brokenaxes
Create matplotlib plots with broken axes
Stars: ✭ 266 (+885.19%)
Mutual labels:  matplotlib, plotting
Mplcyberpunk
"Cyberpunk style" for matplotlib plots
Stars: ✭ 762 (+2722.22%)
Mutual labels:  matplotlib, plotting
geneview
Genomics data visualization in Python by using matplotlib.
Stars: ✭ 38 (+40.74%)
Mutual labels:  matplotlib, plotting
Scientific Visualization Book
An open access book on scientific visualization using python and matplotlib
Stars: ✭ 6,336 (+23366.67%)
Mutual labels:  matplotlib, plotting
Cmasher
Scientific colormaps for making accessible, informative and 'cmashing' plots
Stars: ✭ 149 (+451.85%)
Mutual labels:  matplotlib, plotting
Matplotlib
matplotlib: plotting with Python
Stars: ✭ 14,738 (+54485.19%)
Mutual labels:  matplotlib, plotting
texfig
Utility to generate PGF vector files from Python's Matplotlib plots to use in LaTeX documents.
Stars: ✭ 58 (+114.81%)
Mutual labels:  matplotlib, plotting
microfilm
Creating figures and animations for multi-channel images with a focus on microscopy.
Stars: ✭ 22 (-18.52%)
Mutual labels:  matplotlib, plotting
Joypy
Joyplots in Python with matplotlib & pandas 📈
Stars: ✭ 322 (+1092.59%)
Mutual labels:  matplotlib, plotting
cplot
🌈 Plot complex functions
Stars: ✭ 75 (+177.78%)
Mutual labels:  matplotlib, plotting
Adjusttext
A small library for automatically adjustment of text position in matplotlib plots to minimize overlaps.
Stars: ✭ 731 (+2607.41%)
Mutual labels:  matplotlib, plotting
joypy
Joyplots in Python with matplotlib & pandas 📈
Stars: ✭ 418 (+1448.15%)
Mutual labels:  matplotlib, plotting
SciPlot-PyQt
A Matplotlib-wrapped user-interface for creating and editing publication-ready images and plots
Stars: ✭ 32 (+18.52%)
Mutual labels:  matplotlib, plotting
Pandoc Plot
Render and include figures in Pandoc documents using your plotting toolkit of choice
Stars: ✭ 75 (+177.78%)
Mutual labels:  matplotlib, plotting
EOmaps
A library to create interactive maps of geographical datasets
Stars: ✭ 193 (+614.81%)
Mutual labels:  matplotlib, plotting

Expyplot

Inspired by this project: https://github.com/JordiPolo/explot, but I wanted something more transparent.

Documentation can be found at https://hexdocs.pm/expyplot.

Expyplot allows you to use 'all' of the functions in matplotlib.pyplot (in reality, there are some that I left out because they don't make any sense in this context, or are deprecated).

Unfortunately, I have not tested anywhere near all of the functions, but they should mostly work. If any don't work, please open an issue, or better yet, make a fix and open a pull request! This library is simple enough that you should be able to grok it without too much effort.

Perhaps the most limiting thing about this library is that it currently has to convert return values from the matplotlib functions into strings before sending them back to Elixir, so rather than returning true, you will get "True", and good luck piecing back to gether complicated objects. The reason I went this route is that JSON is unable to parse pretty much any complicated data type that comes back from a matplotlib function, and I didn't feel like writing a JSON parser. If you want to do something about it, please by all means, write a JSON parser capable of serializing all the different return types from matplotlib functions: the python side of this library is very simple - it is located in priv/mat.py.

Differences

Unfortunately (or rather, fortunately if we are celebrating linguistic diversity!), I could not attain complete transparency. This is a list of some notable differences between this library and the real matplotlib.pyplot:

  • Return values are strings currently
  • Variable arguments must be wrapped in a list, so: plt.plot(a, b) becomes Plot.plot([a, b]), but especially notice: Plot.plot([[1..10], other_args])
  • Named args and keyword args are atoms: Plot.grid(b: true), though they don't have to be, so: Plot.plot([[1..10], "r+"])
  • Keyword args that are not keyword only arguments must be written with keywords, you can't do them positionally, so while plt.grid(True) works in Python, you have to name the argument in Elixir: Plot.grid(b: true); if you ever get the error: "argument error: :erlang.++(something, [])", this is the reason. You need to rewrite the argument list as a keyword list.
  • Any keyword argument or named argument that starts with a capital letter needs to be renamed with an underscore: Fs -> :_Fs

Installation

You must have python3 installed and in your path

You must also pip3 install PyQt5 and matplotlib: pip3 install PyQt5, pip3 install matplotlib, or however you install packages for python3 on your particular system.

def deps do
  [{:expyplot, "~> 1.1.2"}]
end

Examples

Examples taken from http://matplotlib.org/examples/pylab_examples and then rewritten in Elixir to use this Expyplot.

To run the examples, start an iex -S mix session and run:

Code.load_file "./path/to/example/EXAMPLE.exs"

Histogram

defmodule HistogramExample do
  alias Expyplot.Plot

  {mu, sigma} = {100, 15}
  x = 1..10_000 |> Stream.map(fn(_) -> Statistics.Distributions.Normal.rand(mu, sigma) end) |> Enum.to_list

  Plot.hist(x, bins: 50, normed: 1, facecolor: :green, alpha: 0.75)
  Plot.xlabel("Smarts")
  Plot.ylabel("Probability")
  Plot.title("IQ Scores")
  Plot.axis_set([40, 160, 0, 0.03])
  Plot.grid(b: true)

  Plot.show()
end

Histogram

Subplots

defmodule SpectralExample do
  alias Expyplot.Plot

  dt = 0.01
  fs = 1 / dt
  t = Stream.unfold(0, fn(acc) -> {acc, acc + dt} end) |> Stream.take_while(&(&1 < 10)) |> Enum.to_list
  nse = t |> Enum.map(fn(_) -> Statistics.Distributions.Normal.rand() end) |> Enum.to_list
  r = t |> Enum.map(&(Statistics.Math.exp(- &1 / 0.05)))

  cnse = nse |> Enum.map(&(&1 * Enum.random(r))) |> Enum.take(length(t)) # fake convolution. I didn't feel like writing a functional convolution.
  s = t |> Enum.map(&(:math.sin(2 * Statistics.Math.pi * &1))) |> Enum.zip(cnse) |> Enum.map(fn {el1, el2} -> el1 + el2 end)

  Plot.subplot([3, 2, 1])
  Plot.plot([t, s])

  Plot.subplot([3, 2, 1])
  Plot.plot([t, s])

  Plot.subplot([3, 2, 3])
  Plot.magnitude_spectrum(s, _Fs: fs)

  Plot.subplot([3, 2, 4])
  Plot.magnitude_spectrum(s, _Fs: fs, scale: :dB)

  Plot.subplot([3, 2, 5])
  Plot.angle_spectrum(s, _Fs: fs)

  Plot.subplot([3, 2, 6])
  Plot.phase_spectrum(s, _Fs: fs)

  Plot.show()
end

Subplots

Zorder/Scatterplots

defmodule ZorderExample do
  alias Expyplot.Plot

  x = 1..20 |> Enum.map(fn(_) -> Statistics.Distributions.Normal.rand() end) |> Enum.to_list
  y = 1..20 |> Enum.map(fn(_) -> Statistics.Distributions.Normal.rand() end) |> Enum.to_list

  Plot.figure()
  Plot.subplot([2, 1, 1])
  Plot.plot([x, y, :r], [lw: 3])
  Plot.scatter(x, y, [s: 120])
  Plot.title("Lines on top of dots")

  Plot.subplot([2, 1, 2])
  Plot.plot([x, y, :r], [zorder: 1, lw: 3])
  Plot.scatter(x, y, [s: 120], [zorder: 2])
  Plot.title("Dots on top of lines")

  Plot.show()
end

Zorder

Bar Graph

defmodule BarExample do
  alias Expyplot.Plot

  men_means = [20, 35, 30, 35, 27]
  women_means = [25, 32, 34, 20, 25]
  men_std = [2, 3, 4, 1, 2]
  women_std = [3, 5, 2, 3, 3]
  ind = 0..4
  width = 0.35
  yticks = Stream.unfold(0, fn(acc) -> {acc, acc + 10} end) |> Stream.take_while(&(&1 < 81)) |> Enum.to_list

  Plot.bar(ind, men_means, [width: width], color: "#d62728", yerr: men_std, label: "Men")
  Plot.bar(ind, women_means, [width: width, bottom: men_means], yerr: women_std, label: "Women")
  Plot.ylabel("Scores")
  Plot.title("Scores by group and gender")
  Plot.xticks([ind, {"G1", "G2", "G3", "G4", "G5"}])
  Plot.yticks([yticks])
  Plot.legend()
  Plot.show()
end

Bar Graph

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].