Reputation: 1
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. How do I fix this?
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.
Upvotes: 0
Views: 37