Plotting using PolyCollection in matplotlib

Karthik Venkatesh

I am trying to plot a 3 dimensional plot in matplotlib. I have to plot Frequency vs Amplitude Distribution for four (or multiple) Radii in a single 3D plot. I was looking at PolyCollection command available in matplotlib.collections and I also went through the example but I do not know how to use the existing data to arrive at the plot.

The dimensions of the quantities that I have are,

Frequency : 4000 x 4, Amplitude : 4000 x 4, Radius : 4

I would like to plot something like, enter image description here

With X axis being Frequencies, Y axis being Radius, and Z axis being Amplitudes. How do I go about solving this problem?

Ajean

PolyCollection expects a sequence of vertices, which matches your desired data pretty well. You don't provide any example data, so I'll make some up for illustration (my dimension of 200 would be your 4000 .... although I might consider a different plot than this if you have so many data points):

import matplotlib.pyplot as plt
from matplotlib.collections import PolyCollection
from mpl_toolkits.mplot3d import axes3d
import numpy as np

# These will be (200, 4), (200, 4), and (4)
freq_data = np.linspace(0,300,200)[:,None] * np.ones(4)[None,:]
amp_data = np.random.rand(200*4).reshape((200,4))
rad_data = np.linspace(0,2,4)

verts = []
for irad in range(len(rad_data)):
    # I'm adding a zero amplitude at the beginning and the end to get a nice
    # flat bottom on the polygons
    xs = np.concatenate([[freq_data[0,irad]], freq_data[:,irad], [freq_data[-1,irad]]])
    ys = np.concatenate([[0],amp_data[:,irad],[0]])
    verts.append(list(zip(xs, ys)))

poly = PolyCollection(verts, facecolors = ['r', 'g', 'c', 'y'])
poly.set_alpha(0.7)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# The zdir keyword makes it plot the "z" vertex dimension (radius)
# along the y axis. The zs keyword sets each polygon at the
# correct radius value.
ax.add_collection3d(poly, zs=rad_data, zdir='y')

ax.set_xlim3d(freq_data.min(), freq_data.max())
ax.set_xlabel('Frequency')
ax.set_ylim3d(rad_data.min(), rad_data.max())
ax.set_ylabel('Radius')
ax.set_zlim3d(amp_data.min(), amp_data.max())
ax.set_zlabel('Amplitude')

plt.show()

Most of this is straight from the example you mention, I just made it clear where your particular datasets would lie. This yields this plot: example PolyCollection plot

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Creating colormap based on strings in dataframe column while plotting using matplotlib

From Java

Plotting with seaborn using the matplotlib object-oriented interface

From Dev

Plotting Pandas DataFrames in to Pie Charts using matplotlib

From Dev

Plotting stacked histograms in python using matplotlib

From Dev

Plotting a graph using matplotlib with two lists

From Dev

plotting dynamic data using matplotlib

From Dev

Plotting multiple line graph using pandas and matplotlib

From Dev

plotting circle in the graph using matplotlib

From Dev

Plotting to 1 figure using multiple functions with Matplotlib, Python

From Dev

Plotting data from CSV files using matplotlib

From Dev

continuous 3d plotting using matplotlib

From Dev

Plotting datetime output using matplotlib

From Dev

Plotting terrain as background using matplotlib

From Dev

Plotting functions from a list using matplotlib

From Dev

Plotting a polynomial using Matplotlib and coeffiecients

From Dev

Plotting a wire frame sphere using MatPlotLib

From Dev

Plotting images side by side using matplotlib

From Dev

Plotting points between ranges using matplotlib

From Dev

Annotating a Matplotlib Polycollection bar timeline

From Dev

Plotting multiple line graph using pandas and matplotlib

From Dev

Using matplotlib Polycollection to plot data from csv files

From Dev

Plotting datetime output using matplotlib

From Dev

Plotting functions from a list using matplotlib

From Dev

Plotting a polynomial using Matplotlib and coeffiecients

From Dev

Plotting Coordinate Lines Using Matplotlib

From Dev

Plotting [x,y] using matplotlib

From Dev

Issue plotting Seaborn and Matplotlib figures using loop

From Dev

Plotting Horizontal Line Using Subplots Matplotlib

From Dev

Plotting side by side charts using matplotlib using

Related Related

  1. 1

    Creating colormap based on strings in dataframe column while plotting using matplotlib

  2. 2

    Plotting with seaborn using the matplotlib object-oriented interface

  3. 3

    Plotting Pandas DataFrames in to Pie Charts using matplotlib

  4. 4

    Plotting stacked histograms in python using matplotlib

  5. 5

    Plotting a graph using matplotlib with two lists

  6. 6

    plotting dynamic data using matplotlib

  7. 7

    Plotting multiple line graph using pandas and matplotlib

  8. 8

    plotting circle in the graph using matplotlib

  9. 9

    Plotting to 1 figure using multiple functions with Matplotlib, Python

  10. 10

    Plotting data from CSV files using matplotlib

  11. 11

    continuous 3d plotting using matplotlib

  12. 12

    Plotting datetime output using matplotlib

  13. 13

    Plotting terrain as background using matplotlib

  14. 14

    Plotting functions from a list using matplotlib

  15. 15

    Plotting a polynomial using Matplotlib and coeffiecients

  16. 16

    Plotting a wire frame sphere using MatPlotLib

  17. 17

    Plotting images side by side using matplotlib

  18. 18

    Plotting points between ranges using matplotlib

  19. 19

    Annotating a Matplotlib Polycollection bar timeline

  20. 20

    Plotting multiple line graph using pandas and matplotlib

  21. 21

    Using matplotlib Polycollection to plot data from csv files

  22. 22

    Plotting datetime output using matplotlib

  23. 23

    Plotting functions from a list using matplotlib

  24. 24

    Plotting a polynomial using Matplotlib and coeffiecients

  25. 25

    Plotting Coordinate Lines Using Matplotlib

  26. 26

    Plotting [x,y] using matplotlib

  27. 27

    Issue plotting Seaborn and Matplotlib figures using loop

  28. 28

    Plotting Horizontal Line Using Subplots Matplotlib

  29. 29

    Plotting side by side charts using matplotlib using

HotTag

Archive