How can i delete a specific axis?

Plotly.newPlot("myDiv",[],{title: "Multiple Y-Axis Plot"});

var trace1 =
{
  x: [1, 2, 3],
  y: [40, 50, 60],
  name: 'yaxis data',
  type: 'scatter'
};

var trace2 =
{
  x: [2, 3, 4],
  y: [4, 5, 6],
  name: 'yaxis2 data',
  yaxis: 'y2',
  type: 'scatter'
};

var yaxis1 =
{
	title: 'yaxis1',
  //position: 0,
  side: "left"
};

var layout1 =
{
	yaxis1: yaxis1,
};

var yaxis2 =
{
  title: 'yaxis2 title',
  titlefont: {color: 'rgb(148, 103, 189)'},
  tickfont: {color: 'rgb(148, 103, 189)'},
  overlaying: 'y1',
  side: 'right',
  position: 1,
};

var layout2 =
{
	yaxis2: yaxis2
};

Plotly.relayout("myDiv", layout1);
Plotly.addTraces("myDiv", [trace1]);

Plotly.relayout("myDiv", layout2);
Plotly.addTraces("myDiv", [trace2]);

I can put new Yaxis on graph but how can i delete one of them?

Plotly.relayout(gd, 'yaxis2', null);

should do the trick

1 Like

Hi
thanks for your fast response. Now it works but the yaxis is now on the standard y axis position?
It removed the axis from position and deleted the layout but the axis is still there ?
i solved it u mentioned it already : first deleteTraces then relayout

 Plotly.deleteTraces();

Plotly.relayout();

Hi there- the code that you’ve outlined doesn’t seem to work for me. I can delete a trace just fine, but when I set a dynamically-added yaxis to null, it doesn’t disappear from my web page?

My code is basically this:

            Plotly.deleteTraces('graphDiv', [1]);
            Plotly.relayout('graphDiv', 'yaxis3', null);
            Plotly.redraw('graphdiv')

The trace deletes correctly, but yaxis3 remains on the page, even after I call relayout or redraw. I am maybe missing a step?

Thank you so much!
-Aubrey

Can you share a full reproducible example?

Thank you so much for your quick reply!

Here’s a link to a Fiddle that illustrates the issue I’m seeing:
https://jsfiddle.net/jqwwhfu1/

If you click the “Add Series 1” and “Add Series 2” buttons, you can see it adds to traces to my plot, and the second trace is on axis ‘yaxis3’ on the right side. If you click the 'Remove Series 1" button, you can see that the data is removed from the chart, but yaxis3 remains on the right side, even though I am setting it to null via a call to relayout.

Any assistance you can provide is great appreciated. Thank you!

Hmm interesting. Thanks for posting.

Looks like there’s a race condition between deleteTraces and relayout.

I was able to get the desired behavior by calling relayout before deleteTraces. See https://jsfiddle.net/jqwwhfu1/1/

That said, the two operations shouldn’t be order-dependent. We’ll look into this further.

Hi sorry for reopen this post but I’m facing the same problem and maybe you have a solution.

I want to delete a specific axis but when I try to set it to null the graph doesn’t change.
Here I share a simple example:
Axis delete example

The best approach I have is setting the axis visibility to false.
Thank you in advance.