#python #matplotlib #3d #bar-chart #xticks
Вопрос:
может кто-нибудь, пожалуйста, помочь мне изменить вышеупомянутые вещи. Я довольно новичок в python и сам не смог решить эту проблему. Мои сюжеты выглядят так::
но они мне нужны больше вот так:
Do I have to change only the xticks spacing or the global layout of my plot? And can somebody maybe help me to center my bars right on the ticks. It seems they are a bit off center but I couldn’t fix that too.
Thanks in advance for any help I’ll receive.
The following code is just a part of a bigger script to read .txt and transform the given data. If further information is needed let me know.
#Creation of 3D bar plot
column = ['$x_1
,'$x_2
,'$x_3
]
row = ['$y_{10}
,'$y_9
,'$y_8
,'$y_7
,'$y_6
,'$y_5
,'$y_4
,'$y_3
,'$y_2
,'$y_1
]
fig = plt.figure(figsize=(6,6))
fig.subplots_adjust(right=0.9)
ax = Axes3D(fig)
ax.dist = 13
fig.add_axes(ax)
#Set up a mesh of positions
xpos = np.arange(0,3,1)
ypos = np.arange(0,10,1)
xpos, ypos = np.meshgrid(xpos 0.25, ypos 0.25/2)
#Convert to 1D array
xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros_like(xpos) #or: zpos = np.zeros(30)
dx = 0.25 * np.ones_like(zpos)
dy = 3*dx.copy()
dz = potential.flatten()
#Normalisation of values, as colourmap only recognises values between 0 and 1
### Change color here
colours = plt.cm.viridis((potential.flatten() - minimum_potential)/(maximum_potential-minimum_potential))
ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color=colours, alpha=0.7)
#ticksx = np.arange(0.5,2.5,1)
ticksx = np.arange(0.5, 3.5, 1)
plt.xticks(ticksx, column)
#ticksy = np.arange(0.5,10,1)
ticksy = np.arange(0.5, 10.5, 1)
plt.yticks(ticksy, row)
ax.yaxis.set_tick_params(labelsize=10)
ax.set_xlabel('')
ax.set_ylabel('')
ax.set_zlabel('voltage')
ax.set_zlim(0,maximum_potential)
plt.savefig(
'%s_%s'%(output_name,i),
dpi=300,
pad_inches = 0.05,
#transparent=True,
)