Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Reversed x axis

I’m plotting some data and the x axis keeps reversing.

The bigger values of the x axis are on the left and the smaller values are on the right hand side

I’m just plotting 4 scatter graphs with error bars

x,y,error_y,error_x

Fourmond1978.tot
6.70000E-08,170.0,20.0,0.0
Fourmond1978A001.tot
7.20000E-08,1340.0,40.0,0.0
Jarczyk1961.tot
2.53000E-08,0.048,0.015,0.0
Mughabghab2006.tot
2.53000E-08,0.0385,0.003,0.0

is there any way of forcing the axis to stay with the smallest numbers on the left and the largest on the right?

This looks strange.

Could you provide a reproducible code snippet?

Thanks for the response.

The graph reads CSV values from a server and passes the values to a function to plot.

I’m still a beginner with JS however the x,y,error_x ,error_y and legend text are passed to a function for plotting.

this is the function

function makeScatterPlotly( x, y ,dy,dx,legend ){
var plotDiv = document.getElementById(“plot”);
var traces2 = [{
x: x,
y: y,
mode: ‘markers’,
error_y: {
type: ‘data’,
array: dy,
visible: true
},
error_x: {
type: ‘data’,
array: dx,
visible: true
},
type: ‘scatter’,
name: legend,
marker: {
size: 8
},
}];
var layout = {
showlegend: true,
autosize: true,
width: w,
height: h/1.5,
margin: {
t: 20
},
xaxis: {
type: log_x,
title: xaxis_title,
borderwidth: ‘50’,
exponentformat: ‘e’,
showline: true,
rangemode: ‘tozero’,
linecolor: ‘#969696’,
linewidth: 4,
autorange: true,
mirror: true,
zeroline: false
},
yaxis: {
type: log_y,
title: ‘Cross section (barns)’,
exponentformat: ‘e’,
showexponent: ‘All’,
borderwidth: ‘50’,
showline: true,
rangemode: ‘nonnegative’,
linecolor: ‘#969696’,
linewidth: 4,
autorange: true,
mirror: true,
zeroline: false
}
};

  Plotly.plot('myDiv', traces2,layout,{displayModeBar: true},{showLink: false});
};

I suspect that something is wrong with how you specified the xaxis type. What’s the value of log_x ?

Here’s a working example: http ://codepen.io/etpinard/pen/vGLJRo

I think it might have been the rangemode: ‘tozero’, setting which was struggling, I guess this makes sense with a log scale plot. Many thanks for the help again

the log_x and log_y variables are set to ‘log’