admin管理员组文章数量:1123003
I have latitude and longitude coordinates in UTM with some data associated with them in a .csv file.
I want to make a 3d bar graph with the height's representing an area's associated data value. I made a 3d bar graph using matplotlib and gave it a colormap following the verified reply to this question. However, the bars do not look as nice as the ones in this post. Some appear not to be anchored i.e. "floating," some appear to be transparent everywhere except on top. They seem to overlap in unnatural ways. I have attached this plot. 3d bar plot with floating and transparent bars How do I fix this?
I also noticed this issue in this post. The bar graph at the bottom has these "floating" bars.
I have tried different colormaps but the problem persists. I have attached here the code I used to produce the plot.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
df = pd.read_csv(example.csv)
lat = df['lat']
lon = df['lon']
data = df['data']
resolution = 375
xx = np.arange(min(lon), max(lon)+resolution, resolution)
yy = np.arange(max(lat), min(lat)-resolution, -resolution)
_xx, _yy = np.meshgrid(xx, yy)
_dz = np.zeros_like(_xx)
for i, datum in enumerate(data):
current_x = lon[i]
current_y = lat[i]
col = np.where(xx == current_x)
row = np.where(yy == current_y)
_dz[row, col] = datum
x = _xx.flatten()
y = _yy.flatten()
z = np.zeros_like(x)
dx = np.full_like(x, resolution)
dy = np.full_like(x, resolution)
dz = _dz.flatten()
cmap = cm.plasma
rgba = [cmap(i/max(data)) for i in dz]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.bar3d(x, y, z, dx, dy, dz, color=rgba)
I am not sure if the issue is reproduceable without my data but the lat and lon coordinates are in UTM, and all the data are between 0.3 and 4.
本文标签: python3d Bar Plot in Matplotlib quotfloatingquot bars and other issuesStack Overflow
版权声明:本文标题:python - 3d Bar Plot in Matplotlib: "floating" bars and other issues - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736539881a1944373.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论