简体   繁体   English

如何获取散景图像以像matplotlib一样在左上角绘制原点?

[英]How to get bokeh images to plot origin in top left like matplotlib?

How can bokeh be used to plot images with the origin in the top left like matplotlib? 散景如何用于绘制像matplotlib一样位于左上角的原点图像?

I can accomplish this by rotating and transposing the 2d array, but is there a way to do this without modifying the array? 我可以通过旋转和转置2d数组来完成此操作,但是有没有一种方法可以在不修改数组的情况下执行此操作? (Modifying the array isn't ideal, because then the axis labels don't match the original data.) (修改数组不是理想的,因为轴标签与原始数据不匹配。)

from bokeh.plotting import figure, output_file, show
import matplotlib.pyplot as plt
import numpy as np

img = np.zeros((5,5), dtype=np.int8)
img[0][0] = 250 
img[0][1] = 250 
img[0][4] = 500
img[0][3] = 500 
img[1][4] = 500 

output_file("default.html")
plot1 = figure(x_range=(0, img.shape[0]), y_range=(0, img.shape[1]))
plot1.image(image=[img], x=0, y=0, dw=img.shape[0], dh=img.shape[1], palette="Spectral10")
show(plot1)

output_file("rotated_transpose.html")
plot2 = figure(x_range=(0, img.shape[0]), y_range=(0, img.shape[1]))
plot2.image(image=[np.rot90(np.transpose(img))], x=0, y=0, dw=img.shape[0], dh=img.shape[1], palette="Spectral10")
show(plot2)

plt.imshow(img, cmap=plt.get_cmap('Spectral'), interpolation="nearest")
plt.show()

在此处输入图片说明

I've tried setting the y range in reverse and specifying the axis locations, but this still doesn't match the matplotlib coordinate system: 我尝试将y范围反向设置并指定轴位置,但这仍然与matplotlib坐标系不匹配:

plot3 = figure(x_range=(0, img.shape[0]), y_range=(img.shape[1], 0), x_axis_location='above', y_axis_location='left')
plot3.image(image=[img], x=0, y=0, dw=img.shape[0], dh=img.shape[1], palette="Spectral10")
show(plot3)

Same issue with Bokeh image plot.The only thing that worked for me was adding img=np.flipud(img) before plotting img. 散景图像图也存在同样的问题。对我唯一有效的方法是在绘制img之前添加img=np.flipud(img) Hope that helps ! 希望能有所帮助!

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

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