Dear developers,

I wrote a code (using different examples), that is plotting together:

a 3d barplot with a smooth line that follows the "points" of bars.

I could not find something similar, therefore, i am sending you this

example.

You may edit some sections if you find something wrong.

Sorry for my english - not my primary language.

#The following plot presents a 3d barplot together

with a smooth line that follows the "points" of bars.

#needed modules

import csv

import pandas as pandas

import numpy as np

from mpl_toolkits.mplot3d import Axes3D

import matplotlib.pyplot as plt

from matplotlib import cm

from scipy.interpolate import spline

#here, we are importing a simple datafile, csv type. data are comma

seperated

#Also, we are importing only 1st, 2nd and 4th columns. We can call

these data now by thie new name, 'io'.

#io = pandas.read_csv('test.csv', sep=",",usecols=(1,2,3,4)) #not available

#io = io[np.isfinite(io['alice'])] #not available

#We define a new name for the column that is named 'alice' inside 'io'

dataset.

result=([9,6,14,7,16,4,14,19,16,7,13,10,15,16,19,27,7,6])

#we need to make these data 'array type'

result = np.array(result)

#we now define the dimensions of our figure/plot, as well its dpi

fig=plt.figure(figsize=(14, 6), dpi=150)

#This line defines our first plot, afterwards, the '112' will define our

second plot.

ax1=fig.add_subplot(111, projection='3d')

#we define here labels

xlabels =np.array([9,6,14,7,16,4,14,19,16,7,13,10,15,16,19,27,7,6])

xpos = np.arange(xlabels.shape[0])

ylabels = np.array(['series A'])

ypos = np.arange(ylabels.shape[0])

xposM, yposM = np.meshgrid(xpos, ypos, copy=False)

zpos=result

zpos = zpos.ravel()

#this defines the dimensions of the actual boxes, you can play with

these values.

dx=0.7

dy=0.7

dz=zpos

#here, we define ticks, they are placed in the 'middle' of each bar

ax1.w_xaxis.set_ticks(xpos + dx/2.)

ax1.w_xaxis.set_ticklabels(xlabels)

ax1.w_yaxis.set_ticks(ypos + dy/2.)

ax1.w_yaxis.set_ticklabels(ylabels)

#here we define the colors of the bars, rainbow style, you can play with

these numbers

values = np.linspace(0.2, 1., xposM.ravel().shape[0])

colors = cm.rainbow(values)

#figure subtitle

fig.suptitle('test title', fontsize=20)

#here, we define in the x axis the size of its ticks, its numbers

ax1.tick_params(axis='x', which='major', pad=15,labelsize=6)

#Here, we define the limits of y axis,

#NOTE that this defines WHERE bars will be placed IN relation to the

rest figure, their offset point

plt.ylim((-2,5))

#this says if the grid will be printed

plt.grid(True)

#this defines the placement of the 3d plot in its placeholders, in the

surrounding white space

plt.subplots_adjust(left=0.0, right=1.0, bottom=0.0, top=1.0)

#this is the actual command to define the plot, all 6 parameters that we

previously defined, are placed here.

#colors is an extra parameter

ax1.bar3d(xposM.ravel(), yposM.ravel(), dz*0, dx, dy, dz, color=colors)

#here we define that we will place a second plot

ax1=fig.add_subplot(112, projection='3d')

#here we say to produce numbers from 0 according to how many data exist

in our 'result'

x=np.arange(0, len(result))

#here, i apply a math trick, in order to get the line a little higher,

out of the bars

x=x+0.4

y=result

#here, i try to center the linein relation to the top of bars.

y=y+5

#here, i try to produce more points in order to make the line to look

nicer.

x_smooth=np.linspace(x.min(),x.max(), 100)

y_smooth=spline(x,y, x_smooth)

#here, i try to produce a 'z' array of so many zeros as the length of

'x_smooth'

z=np.linspace(0, 0, len(x_smooth))

#here, we define the parameters of the second plot.

#note that 'ax1' symbol is duplicated, in order to plot the line in the

same plot with the barplot.

ax1.plot(x_smooth,z,y_smooth)

#here, finally, we will check our results, visually!

plt.show()

???..

For any question, request, comment, or statistical analysis you can

communicate directly with me by using:

???

*estatisticseu at gmail.com*

???

Statistical Articles: eXplained Statistics <http://estatistics.eu/articles/>

EstatisticsEU Facebook page to find some other statistical goodies!

<https://www.facebook.com/estatisticseu/>

-------------- next part --------------

An HTML attachment was scrubbed...

URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20151103/4c65032b/attachment-0001.html>

-------------- next part --------------

A non-text attachment was scrubbed...

Name: not available

Type: image/png

Size: 1022 bytes

Desc: not available

URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20151103/4c65032b/attachment-0004.png>

-------------- next part --------------

A non-text attachment was scrubbed...

Name: not available

Type: image/png

Size: 10371 bytes

Desc: not available

URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20151103/4c65032b/attachment-0005.png>

-------------- next part --------------

A non-text attachment was scrubbed...

Name: not available

Type: image/png

Size: 4470 bytes

Desc: not available

URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20151103/4c65032b/attachment-0006.png>

-------------- next part --------------

A non-text attachment was scrubbed...

Name: not available

Type: image/png

Size: 2441 bytes

Desc: not available

URL: <http://mail.python.org/pipermail/matplotlib-devel/attachments/20151103/4c65032b/attachment-0007.png>