Hi All, I am trying to 3D surface plot the data from a .csv file. there is already a reference plot drawn with this data (seems it was done by some windows app) and I am trying to do the same with linux (in fact on Raspberry Pi) with matplot library. I have attached the .csv file for reference. Original plot (with some microsoft tool) is as below. and when I plot the same data with matplotlib, the plot is as below. Seems the plotting is ok, but for the layer of light orange patches - not sure, what is causing this. My python code is as below. Let me know if you have any suggestion for me. from mpl_toolkits.mplot3d import Axes3D import matplotlib import matplotlib.pyplot as plt from matplotlib import cm from matplotlib.ticker import LinearLocator, FormatStrFormatter import numpy as np import csv X = [] Y = [] Z = [] #Read the selected file with open ('Plasma.csv', 'r') as csvfile: plots = csv.reader (csvfile, delimiter=',') for row in plots: X.append(float(row[0])) Y.append(float(row[1])) Z.append(float(row[2])) #Getting ready for the dispaly fig = plt.figure() ax = fig.gca(projection='3d') #Set the labels... ax.set_xlabel('X (mm)') ax.set_ylabel('Y (mm)') ax.set_zlabel('CPD (mV)') #Setting the places properly... tmp_planes = ax.zaxis._PLANES ax.zaxis._PLANES = (tmp_planes[2], tmp_planes[3], tmp_planes[0], tmp_planes[1], tmp_planes[4],tmp_planes[5]) # Make data. X, Y = np.meshgrid(X, Y) #Plot surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm, linewidth=0) plt.show() With best regards, Phani. _______________________________________________ Matplotlib-devel mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-devel Plasma.csv (5K) Download Attachment |
Hi Phani,
Please find attached a modified version of your script that should help (hopefully). It produces the attached PNG. I think that your problem is how to reshape your data before feeding them to the 3d plotting routine. Besides, I am no mplot3d expert, but I wonder if there would be a way to set the z-axis on the left **without** relying on private attributes (this is often very **not** future-proof as such features can be changed without warning in a future version of the library). Best, Adrien On 03/12/2018 06:19 AM, Phani Kumar wrote: > Hi All, > > I am trying to 3D surface plot the data from a .csv file. there is > already a reference plot drawn with this data (seems it was done by some > windows app) and I am trying to do the same with linux (in fact on > Raspberry Pi) with matplot library. > > I have attached the .csv file for reference. > > Original plot (with some microsoft tool) is as below. > > and when I plot the same data with matplotlib, the plot is as below. > > > Seems the plotting is ok, but for the layer of light orange patches - > not sure, what is causing this. My python code is as below. Let me know > if you have any suggestion for me. > > from mpl_toolkits.mplot3d import Axes3D > import matplotlib > import matplotlib.pyplot as plt > from matplotlib import cm > from matplotlib.ticker import LinearLocator, FormatStrFormatter > import numpy as np > import csv > > X = [] > Y = [] > Z = [] > > #Read the selected file > with open ('Plasma.csv', 'r') as csvfile: > plots = csv.reader (csvfile, delimiter=',') > for row in plots: > X.append(float(row[0])) > Y.append(float(row[1])) > Z.append(float(row[2])) > > #Getting ready for the dispaly > fig = plt.figure() > ax = fig.gca(projection='3d') > > #Set the labels... > ax.set_xlabel('X (mm)') > ax.set_ylabel('Y (mm)') > ax.set_zlabel('CPD (mV)') > > > > #Setting the places properly... > tmp_planes = ax.zaxis._PLANES > ax.zaxis._PLANES = (tmp_planes[2], tmp_planes[3], > tmp_planes[0], tmp_planes[1], > tmp_planes[4],tmp_planes[5]) > > # Make data. > X, Y = np.meshgrid(X, Y) > > #Plot > surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm, linewidth=0) > > plt.show() > > > With best regards, > Phani. > > > _______________________________________________ > Matplotlib-devel mailing list > [hidden email] > https://mail.python.org/mailman/listinfo/matplotlib-devel > _______________________________________________ Matplotlib-devel mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-devel |
Hi Adrien,
Thanks a lot. I tried your suggestion and initial got root@phani:/home/pi/SampleExample# python Trial1.py Traceback (most recent call last): File "Trial1.py", line 46, in <module> surf = ax.plot_surface(xx, yy, zz, cmap="inferno") File "/usr/lib/python2.7/dist-packages/mpl_toolkits/mplot3d/axes3d.py", line 1637, in plot_surface polyc = art3d.Poly3DCollection(polys, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/mpl_toolkits/mplot3d/art3d.py", line 476, in __init__ PolyCollection.__init__(self, verts, *args, **kwargs) File "/usr/lib/python2.7/dist-packages/matplotlib/collections.py", line 799, in __init__ Collection.__init__(self, **kwargs) File "/usr/lib/python2.7/dist-packages/matplotlib/collections.py", line 107, in __init__ cm.ScalarMappable.__init__(self, norm, cmap) File "/usr/lib/python2.7/dist-packages/matplotlib/cm.py", line 197, in __init__ self.cmap = get_cmap(cmap) File "/usr/lib/python2.7/dist-packages/matplotlib/cm.py", line 163, in get_cmap % (name, ', '.join(cmap_d.keys()))) ValueError: Colormap inferno is not recognized. Possible values are: Spectral, summer, coolwarm, Wistia_r, pink_r, Set1, Set2, Set3, brg_r, Dark2, prism, PuOr_r, afmhot_r, terrain_r, PuBuGn_r, RdPu, gist_ncar_r, gist_yarg_r, Dark2_r, YlGnBu, RdYlBu, hot_r, gist_rainbow_r, gist_stern, PuBu_r, cool_r, cool, gray, copper_r, Greens_r, GnBu, gist_ncar, spring_r, gist_rainbow, gist_heat_r, Wistia, OrRd_r, CMRmap, bone, gist_stern_r, RdYlGn, Pastel2_r, spring, terrain, YlOrRd_r, Set2_r, winter_r, PuBu, RdGy_r, spectral, rainbow, flag_r, jet_r, RdPu_r, gist_yarg, BuGn, Paired_r, hsv_r, bwr, cubehelix, Greens, PRGn, gist_heat, spectral_r, Paired, hsv, Oranges_r, prism_r, Pastel2, Pastel1_r, Pastel1, gray_r, jet, Spectral_r, gnuplot2_r, gist_earth, YlGnBu_r, copper, gist_earth_r, Set3_r, OrRd, gnuplot_r, ocean_r, brg, gnuplot2, PuRd_r, bone_r, BuPu, Oranges, RdYlGn_r, PiYG, CMRmap_r, YlGn, binary_r, gist_gray_r, Accent, BuPu_r, gist_gray, flag, bwr_r, RdBu_r, BrBG, Reds, Set1_r, summer_r, GnBu_r, BrBG_r, Reds_r, RdGy, PuRd, Accent_r, Blues, autumn_r, autumn, cubehelix_r, nipy_spectral_r, ocean, PRGn_r, Greys_r, pink, binary, winter, gnuplot, RdYlBu_r, hot, YlOrBr, coolwarm_r, rainbow_r, Purples_r, PiYG_r, YlGn_r, Blues_r, YlOrBr_r, seismic, Purples, seismic_r, RdBu, Greys, BuGn_r, YlOrRd, PuOr, PuBuGn, nipy_spectral, afmhot root@bitscope:/home/pi/SampleExample# So I thought the color scheme "inferno" is not supported (or may be not installed in my pi). So I changed it to "coolwarm" and I see the image as below. <http://matplotlib.1069221.n5.nabble.com/file/t5142/plasma.png> Though this is way better than my initial version, still I see only 2 color combination... may be I need to check with color schemes provided in the error message. Thanks a lot any way. Also let me know if you think any suitable color scheme for this kind of gradient. Will check with you on other technical questions after I finish this. Thanks again, With best regards, Phani. -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-devel-f28077.html _______________________________________________ Matplotlib-devel mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-devel |
The error message means you have an old version of matplotlib. Inferno was added in version 1.5. We are currently at verson 2.2.1 (supposedly will be released today?). I would also wonder if your install of numpy is old as well. Chances are, you are hitting on some old forgotten bug. Could you try updating your packages? On Tue, Mar 13, 2018 at 6:49 AM, phanids <[hidden email]> wrote: Hi Adrien, _______________________________________________ Matplotlib-devel mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-devel |
Hi Phani,
I would make the same analysis and suggestion as Ben about the error that you got. About the color map, any rather recent version of Matplotlib (let's say 1.5.3+ or 2+) should have a list of color maps close to the list here: https://matplotlib.org/tutorials/colors/colormaps.html A few of them may be missing if you are not using Matplotlib 2.2+, but that is really a few of them. As your data seem to have only values of the same sign, I would advise for any sequential color scheme rather than a diverging one like "coolwarm" (except if the mid-range value has a very specific meaning that you would want to emphasize). The point of the "viridis" family¹ ("viridis", "inferno", "plasma", "magma", and recently "cividis") is to be perceptually uniform, which should thus be felt quite the same in color or gray scale printing, as well as by colorblind people. Best, Adrien On March 13, 2018 6:29:07 AM PDT, Benjamin Root <[hidden email]> wrote: >The error message means you have an old version of matplotlib. Inferno >was >added in version 1.5. We are currently at verson 2.2.1 (supposedly will >be >released today?). I would also wonder if your install of numpy is old >as >well. Chances are, you are hitting on some old forgotten bug. Could you >try >updating your packages? > >On Tue, Mar 13, 2018 at 6:49 AM, phanids <[hidden email]> >wrote: > >> Hi Adrien, >> >> Thanks a lot. I tried your suggestion and initial got >> >> root@phani:/home/pi/SampleExample# python Trial1.py >> Traceback (most recent call last): >> File "Trial1.py", line 46, in <module> >> surf = ax.plot_surface(xx, yy, zz, cmap="inferno") >> File >"/usr/lib/python2.7/dist-packages/mpl_toolkits/mplot3d/axes3d.py", >> line 1637, in plot_surface >> polyc = art3d.Poly3DCollection(polys, *args, **kwargs) >> File >"/usr/lib/python2.7/dist-packages/mpl_toolkits/mplot3d/art3d.py", >> line 476, in __init__ >> PolyCollection.__init__(self, verts, *args, **kwargs) >> File "/usr/lib/python2.7/dist-packages/matplotlib/collections.py", >line >> 799, in __init__ >> Collection.__init__(self, **kwargs) >> File "/usr/lib/python2.7/dist-packages/matplotlib/collections.py", >line >> 107, in __init__ >> cm.ScalarMappable.__init__(self, norm, cmap) >> File "/usr/lib/python2.7/dist-packages/matplotlib/cm.py", line 197, >in >> __init__ >> self.cmap = get_cmap(cmap) >> File "/usr/lib/python2.7/dist-packages/matplotlib/cm.py", line 163, >in >> get_cmap >> % (name, ', '.join(cmap_d.keys()))) >> ValueError: Colormap inferno is not recognized. Possible values are: >> Spectral, summer, coolwarm, Wistia_r, pink_r, Set1, Set2, Set3, >brg_r, >> Dark2, prism, PuOr_r, afmhot_r, terrain_r, PuBuGn_r, RdPu, >gist_ncar_r, >> gist_yarg_r, Dark2_r, YlGnBu, RdYlBu, hot_r, gist_rainbow_r, >gist_stern, >> PuBu_r, cool_r, cool, gray, copper_r, Greens_r, GnBu, gist_ncar, >spring_r, >> gist_rainbow, gist_heat_r, Wistia, OrRd_r, CMRmap, bone, >gist_stern_r, >> RdYlGn, Pastel2_r, spring, terrain, YlOrRd_r, Set2_r, winter_r, PuBu, >> RdGy_r, spectral, rainbow, flag_r, jet_r, RdPu_r, gist_yarg, BuGn, >> Paired_r, >> hsv_r, bwr, cubehelix, Greens, PRGn, gist_heat, spectral_r, Paired, >hsv, >> Oranges_r, prism_r, Pastel2, Pastel1_r, Pastel1, gray_r, jet, >Spectral_r, >> gnuplot2_r, gist_earth, YlGnBu_r, copper, gist_earth_r, Set3_r, OrRd, >> gnuplot_r, ocean_r, brg, gnuplot2, PuRd_r, bone_r, BuPu, Oranges, >RdYlGn_r, >> PiYG, CMRmap_r, YlGn, binary_r, gist_gray_r, Accent, BuPu_r, >gist_gray, >> flag, bwr_r, RdBu_r, BrBG, Reds, Set1_r, summer_r, GnBu_r, BrBG_r, >Reds_r, >> RdGy, PuRd, Accent_r, Blues, autumn_r, autumn, cubehelix_r, >> nipy_spectral_r, >> ocean, PRGn_r, Greys_r, pink, binary, winter, gnuplot, RdYlBu_r, hot, >> YlOrBr, coolwarm_r, rainbow_r, Purples_r, PiYG_r, YlGn_r, Blues_r, >> YlOrBr_r, >> seismic, Purples, seismic_r, RdBu, Greys, BuGn_r, YlOrRd, PuOr, >PuBuGn, >> nipy_spectral, afmhot >> root@bitscope:/home/pi/SampleExample# >> >> So I thought the color scheme "inferno" is not supported (or may be >not >> installed in my pi). So I changed it to "coolwarm" and I see the >image as >> below. >> >> <http://matplotlib.1069221.n5.nabble.com/file/t5142/plasma.png> >> >> Though this is way better than my initial version, still I see only 2 >color >> combination... may be I need to check with color schemes provided in >the >> error message. >> >> Thanks a lot any way. Also let me know if you think any suitable >color >> scheme for this kind of gradient. >> >> Will check with you on other technical questions after I finish this. >> >> Thanks again, >> >> With best regards, >> Phani. >> >> >> >> -- >> Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-devel- >> f28077.html >> _______________________________________________ >> Matplotlib-devel mailing list >> [hidden email] >> https://mail.python.org/mailman/listinfo/matplotlib-devel >> -- Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté. _______________________________________________ Matplotlib-devel mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-devel |
Hi Benjamin, Adrien,
You guys are awesome !!! //Earlier versions root@phani:/home/pi/SampleExample# python -c 'import matplotlib; print matplotlib.__version__' *1.4.2 * root@phani:/home/pi/SampleExample# python -c "import numpy; print (numpy.__version__)" *1.8.2* did *python -mpip install -U matplotlib* for update and then root@phani:/home/pi/SampleExample# python -c 'import matplotlib; print matplotlib.__version__' *2.2.0* root@phani:/home/pi/SampleExample# python -c "import numpy; print (numpy.__version__)" *1.14.2* But when I run it, I get below warning message... root@phani:/home/pi/SampleExample# python Trial1.py */usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_gtk3.py:181: Warning: Source ID 7 was not found when attempting to remove it GLib.source_remove(self._idle_draw_id)* 1. Still the plotting happens (attached). Googling says there is nothing to worry about the warning. Do you have any suggestion for me? 2. Is there any way I can set the grid color to light blue (as in the original image)? May be it helps in better highlighting the plot (than which is currently white). 3. In original image, also there is a "shade" of the plot on X - axis. Is there any way we can get the shade? Basically it would help to find the range more exactly as the X-Axis would have the scale. 4. This python script, I am calling from QT. Is there any way, I can call matplotlib libraries from QT itself? Thanks a lot, With best regards, Phani. <http://matplotlib.1069221.n5.nabble.com/file/t5142/plasma.png> -- Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-devel-f28077.html _______________________________________________ Matplotlib-devel mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-devel |
Hi Phani,
1. The warning may be simply related to the backend that you are using. You could give a shot to other backends if there are avalaible on your setup. See for example the lines: ```python mpl.use("Qt5Agg") # or TkAgg or any other available backend import matplotlib.pyplot as plt ``` at the top in the attached file `example_v2.png`. 2. For the edge line color, please have a look at the call of `ax.plot_surface` in that script. You can indeed pass keyword arguments like "edgecolor" or "linewidth". 3. I am not sure of what you mean about the shade on the x-axis. 4. I am out of my depth there :/. Also I realized that the trick to pin the z-axis labels onto the left side produces weird grid lines for that axis. Maybe Ben would have a better solution (i.e. a real one...), but in the meantime, I suggested another workaround in the script, which leads to the attached PNG. Best, Adrien On 03/15/2018 02:54 AM, phanids wrote: > Hi Benjamin, Adrien, > > You guys are awesome !!! > > //Earlier versions > root@phani:/home/pi/SampleExample# python -c 'import matplotlib; print > matplotlib.__version__' > *1.4.2 * > > root@phani:/home/pi/SampleExample# python -c "import numpy; print > (numpy.__version__)" > *1.8.2* > > did *python -mpip install -U matplotlib* for update and then > > root@phani:/home/pi/SampleExample# python -c 'import matplotlib; print > matplotlib.__version__' > *2.2.0* > > root@phani:/home/pi/SampleExample# python -c "import numpy; print > (numpy.__version__)" > *1.14.2* > > But when I run it, I get below warning message... > > root@phani:/home/pi/SampleExample# python Trial1.py > > */usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_gtk3.py:181: > Warning: Source ID 7 was not found when attempting to remove it > GLib.source_remove(self._idle_draw_id)* > > 1. Still the plotting happens (attached). Googling says there is nothing to > worry about the warning. Do you have any suggestion for me? > > 2. Is there any way I can set the grid color to light blue (as in the > original image)? May be it helps in better highlighting the plot (than which > is currently white). > > 3. In original image, also there is a "shade" of the plot on X - axis. Is > there any way we can get the shade? Basically it would help to find the > range more exactly as the X-Axis would have the scale. > > 4. This python script, I am calling from QT. Is there any way, I can call > matplotlib libraries from QT itself? > > Thanks a lot, > > With best regards, > Phani. > > <http://matplotlib.1069221.n5.nabble.com/file/t5142/plasma.png> > > > > -- > Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-devel-f28077.html > _______________________________________________ > Matplotlib-devel mailing list > [hidden email] > https://mail.python.org/mailman/listinfo/matplotlib-devel > _______________________________________________ Matplotlib-devel mailing list [hidden email] https://mail.python.org/mailman/listinfo/matplotlib-devel |
Free forum by Nabble | Edit this page |