简体   繁体   English

django-nvd3中绘图轴上的科学表示法

[英]Scientific notation on axes in plot from django-nvd3

I have tried for hours now to find any documentation on this, but it doesn't appear to exist. 我已经尝试了几个小时才能找到与此有关的任何文档,但是它似乎不存在。 After battling for days to get any of the methods for creating and showing plots in Django to work, I finally managed to get nvd3 for django working. 经过数天的努力,让所有在Django中创建和显示绘图的方法都可以使用,我终于设法使nvd3用于Django的工作。 But now I am having problems with the notations on the y axis of my plot. 但是现在我在绘图的y轴上的符号有问题。 Because my values are very small (at most 1.0e-4) I want to use scientific notation with exponentials. 因为我的值很小(最多为1.0e-4),所以我想对指数使用科学计数法。

The command to do what I want appears to be chart.y1Axis.d3.format(".2f") in d3, but I have no clue how to apply this in nvd3. 执行我想要的命令的命令似乎是chart.y1Axis.d3.format(".2f") ,但是我不知道如何在nvd3中应用它。 Does anyone know how to deal implement it? 有人知道如何实施吗?

Also, on the x axis I have the opposite problem that the values are large. 另外,在x轴上,我有相反的问题,即值较大。 Because the plot is log-log the routine puts a ticklabel on 10, 20, 30 40,...100, 200, 300, 400..and so on, but I want it to only plot for every order of magnitude (10, 100, 1000, 10000 etc.). 因为该图是对数对数的,所以例程在10、20、30 40,... 100、200、300、400 ..等上放置了一个ticklabel,依此类推,但我希望它仅针对每个数量级进行绘制(10 ,100、1000、10000等)。 What is the easiest way to automate this? 自动化的最简单方法是什么? Would it work if I tell the routine to always print the ticks for 10, 100, 1000, 10000, and so on up to an exceedingly high value, even though my plot wouldn't reach as high? 如果我告诉例程始终打印10、100、1000、10000等的报价,直到我的图不会达到很高的值,这会行得通吗? How would I do that? 我该怎么做?

This is how the plot looks like right now: 这是当前情节的样子:

地块视图

Use this for scientific notations on y axis 将其用于y轴上的科学计数法

 chart.yAxis.tickFormat(d3.format('.02e'));

for x axis problem try this 对于x轴问题,请尝试此

this will return log for the x values. 这将返回x值的日志。

chart.x(function(d){return Math.log10(dx)}) ; chart.x(function(d){return Math.log10(dx)}) ;

and this will again covert it to normal number, your scale will be logarithmic 这将再次将其转换为正常数字,您的比例将为对数

chart.xAxis.tickFormat(function(d){ return (Math.pow(10,d)).toFixed(2);});

Here is the JSFiddle 这是JSFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM