Home  >  Article  >  Web Front-end  >  plotly.js plotting library introductory tutorial sharing

plotly.js plotting library introductory tutorial sharing

小云云
小云云Original
2018-02-24 09:01:042512browse

This article mainly introduces you to the detailed introductory tutorial of plotly.js drawing library. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.

Plotly

Origin

In the past two days, I wanted to display mathematical function images on the front end. I guess there should be a mature js library. .

So, I simply tried it.

Finally decided to use plotly.js. Others such as function-plot also look good. I will take a look at it when I have time.

Plotly

plotly.js is the open source JavaScript graphing library that powers Plotly.

Plotly can be called the best graphing library to date ,none of them.

Simple case

Code


##

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>plot 绘制图像</title>
</head>
<body>
<p id="tester" style="width:600px;height:250px;"></p>
</body>
<script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script>
<!-- test -->
<script>
  TESTER = document.getElementById(&#39;tester&#39;);
  Plotly.plot(TESTER, [{
    x: [1, 2, 3, 4, 5],
    y: [1, 2, 4, 8, 16]
  }], {
    margin: {t: 0}
  });
</script>
</html>

Effect

Point diagram


Drawing mathematical images

The principles of mathematical image drawing. For example, y = 2*x+1 is actually an image formed by connecting a series of (x,y) points.

Code

##

<p id="math-function" style="width:600px;height:250px;"></p>
<script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script>

<script>
  TESTER = document.getElementById(&#39;math-function&#39;);

  var x = [], y = [];

  for(var i = -10; i < 10; i += 1) {
    x.push(i);
    y.push(2*i+1);
  }

  Plotly.plot(TESTER, [{
    x: x,
    y: y
  }], {
    margin: {t: 0}
  });
</script>

Effect

Function image


Related recommendations:


Share the case of how Python uses plotly to draw data charts (pictures and texts)

The above is the detailed content of plotly.js plotting library introductory tutorial sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn