Plotly.js issue with second Y-axis not properly adjusting scale

I am dealing with a unique dataset that comprises two sets of x-y data. Both sets have x values representing dates within a common range, albeit at different specific points. The y values associated with each set represent entirely distinct data with varying ranges.

  1. One set of y data on the left-hand side is configured to autoscale and utilize the [0,1] domain optimally, while the other set on the right doesn't follow this pattern.

  2. In the graphical user interface (GUI), I selected autoscale for both y axes. However, the left axis displayed some odd range for the data in the GUI and JSON files, despite having autorange=true in the JSON file.

  3. Unlike the left axis, the right axis does not indicate autorange in the GUI.

    
    {<br>
      data:[<br>
        {<br>
          name:"Col2",
          type:"scatter",
          mode:"lines+markers",
          xsrc:"arielbalter:21:4b225a",
          ysrc:"arielbalter:21:10a1f9",
          uid:"d0ee8f"
        },
        {<br>
          name:"Col4",
          type:"scatter",
          mode:"lines+markers",
          xsrc:"arielbalter:21:3aee4d",
          ysrc:"arielbalter:21:6eee6c",
          uid:"502656"
        }
      ],
      layout:{<br>
        yaxis:{<br>
          type:"linear",
          range:[<br>
            -737.9094809575623,
            13174.640480957562
          ],
          autorange:true,
          tickmode:"auto",
          showline:true
        },
        xaxis:{<br>
          type:"date",
          range:[<br>
            1383440400000,
            1434808800000
          ],
          autorange:true
        },
        height:801,
        width:1616,
        autosize:true,
        yaxis2:{<br>
          overlaying:"y",
          side:"right",
          anchor:"x",
          showline:true
        }
      }
    }
    

After generating the JavaScript code automatically, I manually adjusted it to enable autorange:

https://jsfiddle.net/abalter/rre2Lma2/

var trace1 = {
  x: ["2013-12-04 00:00:00.0", "2014-02-10 00:00:00.0", "2014-04-07 00:00:00.0", ...], 
  y: ["12395", "7367", "211", ...], 
  mode: "lines+markers", 
  name: "Col2", 
  type: "scatter", 
  uid: "d0ee8f"
};
var trace2 = {
  x: ["2013-12-04 00:00:00.0", "2013-12-09 00:00:00.0", "2013-12-13 00:00:00.0", ...], 
  y: ["47.673", "47.628", "46.7", ...], 
  mode: "lines+markers", 
  name: "Col4", 
  type: "scatter", 
  uid: "502656"
};
var data = [trace1, trace2];
var layout = {
  autosize: true, 
  height: 761, 
  width: 1616, 
  xaxis: {
    autorange: true, 
    range: [1.38617155299e+12, 1.43454849026e+12], 
    type: "date"
  }, 
  yaxis: {
    autorange: true, 
    showline: true, 
    tickmode: "auto", 
    type: "linear"
  }, 
  yaxis2: {
    anchor: "x", 
    autorange: true, 
    overlaying: "y", 
    showline: true, 
    side: "right"
  }
};
Plotly.plot('plotly-div', data, layout);

Answer №1

Although an old question, I wanted to share my answer. The data sets must be linked to the axes on which they are to be plotted.

It seems that the only way to reference them is as y1, y2, y3...

I inserted "yaxis: 'y2'" into your jsfiddle for the second data set, and the plot significantly improved.

https://jsfiddle.net/yjyea8cg/2/

var trace1 = {
  x: ["2013-12-04 00:00:00.0", "2014-02-10 00:00:00.0", ...], 
  y: ["12395", "7367", ...], 
  mode: "lines+markers", 
  name: "Col2", 
  type: "scatter", 
  uid: "d0ee8f", 
  xsrc: "arielbalter:21:4b225a", 
  ysrc: "arielbalter:21:10a1f9",
};
var trace2 = {
  x: ["2013-12-04 00:00:00.0", "2013-12-09 00:00:00.0", ...], 
  y: ["47.673", "47.628", ...], 
  mode: "lines+markers", 
  name: "Col4", 
  type: "scatter", 
  uid: "502656", 
  xsrc: "arielbalter:21:3aee4d", 
  ysrc: "arielbalter:21:6eee6c",
  yaxis: 'y2',
};
var data = [trace1, trace2];
var layout = {
  autosize: true, 
  height: 761, 
  width: 1616, 
  xaxis: {
    autorange: true, 
    range: [1.38617155299e+12, 1.43454849026e+12], 
    type: "date"
  }, 
  yaxis: {
    autorange: true, 
    showline: true, 
    tickmode: "auto", 
    type: "linear"
  }, 
  yaxis2: {
    anchor: "x", 
    autorange: true, 
    overlaying: "y", 
    showline: true, 
    side: "right"
  }
};
Plotly.plot('plotly-div', data, layout);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to set all UI forms to a readonly/disable mode?

We have a specific requirement where, if the user's access level is set to "READ ONLY", all form input elements should be made readonly. Our coding approach involves using a template HTML that contains widgets which are referenced in the correspondin ...

How can we stop every tab pane in (bootstrap five) from sharing the same scroll position? Each tab is currently synchronized with the scroll position of the others

In Bootstrap 5, the scroll position remains the same when switching between tabs in the tab pane. Whether moving from tab #1 to tab #2, both tabs are at the identical scroll position, failing to preserve each tab's specific location. <div class=&qu ...

Tips for customizing the appearance of your browser's scroll bar:

Is there a way to customize the browser scroll bar using html, css, and js similar to how Chrome does with Control + F? https://i.sstatic.net/62Hju.png I have experimented with adding a fixed position div creating a linear gradient style for the scroll ...

What could be the reason for my Vue application failing to load, even though the mounted event is being triggered

Here's an interesting scenario. The code functions correctly in CodePen and even in Stack Overflow's code renderer, but it fails to work on my GitHub Pages site. No errors are triggered, and the console logs for the created and mounted events ex ...

File uploading functionality using Node.js and AJAX

I've been working on creating a Node.js file uploader that includes an AJAX progress bar. var formidable = require('./formidable'), http = require('http'), sys = require('sys'); http.createServer(function(req, res) { ...

Updating JQuery function after window is resized

click here Currently, I am using slick-slider to showcase content in 3 columns by utilizing flexbox. The aim is to have the slider activated only on mobile view. This means that when the screen size shrinks down to mobile view, the 3 column flexbox transf ...

Generating elements added at various depths within an HTML document with the help of JavaScript

create_new.append("div") .append("form").merge(update_5) .attr("action", d => d.market) .attr("target","_blank") .style("width","100%") .style("height","282") .append("input").merge(update_5) .attr("type","submit") ...

establishing the dimensions of table data cells

I'm facing a challenge with setting the width and height for table data that changes dynamically based on different values. The dimensions of the table itself are not definite, so I need to find a solution. Here's the code snippet I'm curren ...

Next.js presents a challenge with micro frontend routing

In the process of developing a micro frontend framework, I have three Next.js projects - app1, app2, and base. The role of app1 and app2 is as remote applications while base serves as the host application. Configuration for app1 in next.config.js: const ...

The jQuery script that is trying to create a fading effect on an image at intervals is encountering an error message

I am trying to cycle through 4 pictures every 3 seconds while fading them in and out. I have successfully changed the pictures, but when I attempt to use fadeOut, I encounter an error stating "Uncaught TypeError: $(...).fadeOut is not a function" in action ...

Exploring the world of web development with a mix of

var articles = [ {% for article in article_list %} {% if not forloop.first %},{% endif %} { title: "{{ article.title }}", slug: "{{ article.slug }}", content: "{{ article.content }}", auth ...

Tips on employing the sendkeys function in selenium webdriverjs through promise chaining

Here is the coding snippet: driver.get(url).then(function(){ txtFnn = driver.findElement(webdriver.By.xpath(xpath)); return txtFnn; }).then(function(){ txtFnn.sendkeys("12345678"); }) Issue: An error occurred: Typ ...

Sharing dynamic scientific findings through Python publication

I'm uncertain if this inquiry aligns with the theme of this community, yet I am at a loss for where to pose it. While my background doesn't involve web programming, I have recently embarked on a web venture that incorporates various JavaScript l ...

Utilize Jquery to send a preset value through an ajax request

I am working on a select box functionality where the selected option is sent via ajax to a server-side script. The current setup is functioning properly. Here is the code for the select box: <select id="main_select"> <option selecte ...

Unable to access a frame inside an iframe and frameset using JavaScript when both domains are identical

I am attempting to use JavaScript to access an HTML element within a nested frame in an iframe and frameset. The structure of the HTML is as follows: <iframe id="central_iframe" name="central_iframe" (...)> <frameset cols="185, *" border="0" ...

No output from JavaScript loop when trying to print an array

I've been looking all over the place and haven't been able to find a pure JavaScript solution for my problem that I can implement into my code. The issue involves a script that is meant to display an array of images, but currently it only display ...

Scrolling to the top of the Popper component when an element is selected

I am currently utilizing the Autocomplete Material UI control with multiple selections enabled. Here is the code snippet I have created based on this answer: <Autocomplete PopperComponent={PopperMy} ... /> const PopperMy = function (props) ...

Implementing date range filtering in AngularJS model using filters

Within my view, I have the following: <tr dir-paginate="post in posts |orderBy:propertyName:reverse | filter: searchPost | itemsPerPage: pageSize"> <td> {{post.title}} </td> <td> {{post.content}} </td> <td& ...

Encountered an Unhandled Rejection error in react-planner when utilizing threejs: TypeError - url.lastIndexOf function is not recognized

Incorporating react-planner into my React application, I am utilizing a collection of 3D items that are stored in a catalog within my SRC folder, using MTL, OBJ, and texture files. However, upon switching to the 3D viewer, I encountered an error while att ...

Removing the empty option in a select element with ng-model

There's a situation I'm dealing with that involves a select dropdown along with a refresh button and a plus button. The issue arises when clicking the refresh button sets the model to null, while clicking the plus button displays the dropdown wit ...