在matplotlib中,我们可以使用xlim()方法更改x轴的限制。在HoloViews中是否有等效的方法?
我搜索了HV options page,但没有找到任何似乎这样做的内容。
我在Jupyter笔记本中使用以下代码创建了下面的图像:
import numpy as np
import holoviews as hv
hv.notebook_extension('bokeh', width=90)
values = np.array([list of floats])
frequencies, edges = np.histogram(values, 10)
hv.Histogram(frequencies, edges)
如何将x轴限制更改为[0.002,0.016]。
此外,是否可以获得一个图表来返回其当前的x轴限制?
答案 0 :(得分:3)
HoloViews通常只使用您提供的数据范围。因此,更改直方图边界的最简单方法是在np.histogram调用本身中更改它:
SYMIX
如果您只想更改查看范围,也可以直接设置:
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import com.jayway.jsonpath.JsonPath;
public class TestJson {
public static void main(String[] args) throws Exception {
String pathToFile = "file.json";
String plant = "RY1";
File file = openFile(pathToFile);
String erp = readErpFromFile(file, plant);
System.out.println("Erp: " + erp);
}
private static String readErpFromFile(File file, String plant) throws Exception {
List<String> values = JsonPath.read(file, String.format("$.data.mapping.[?(@.plant==%s)].erp", plant));
return values.isEmpty() ? null : values.get(0);
}
private static File openFile(String strPath) throws IOException {
Path path = Paths.get(strPath);
System.out.println("Trying to read file: " + path.toAbsolutePath().toString());
return path.toFile();
}
}
其中范围定义为frequencies, edges = np.histogram(values, 10, range=(0.002, 0.016))
hv.Histogram(frequencies, edges)
。
答案 1 :(得分:1)
最简单的方法可能是在绘图中添加 .opts(xlim =(0.002,0.016)),如下所示:
hv.Histogram((frequencies, edges)).opts(xlim=(0.002, 0.016))
您可以对ylim做同样的事情,例如:
.opts(xlim=(0.002, 0.016), ylim=(0, 300))
这与matplotlib非常相似。