Colormap/color problems with bar3d plot - python
I have written some code to plot the longitude and latitude of towns/cities in the UK with the 3D bar height representing the population of these places. I am trying to also colour code the bars using a colormap so that the variation in population can be more easily seen. However, my code doesnt seem to follow the colormap and instead all the bars have very similar colours - I am not sure where I have gone wrong
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
pop = [189120, 91297, 107123, 107355, 94782, 87590, 142968, 1085810, 117963, 147663, 194189, 187503, 349561, 229700, 535907, 145818, 335145, 110507, 116447, 86011, 88483, 119441, 325949, 106943, 92363, 255394, 109805, 144170, 109185, 468720, 113507, 120046, 104157, 589900, 136362, 88243, 88134, 88855, 91053, 94932, 120256, 162949, 284321, 144957, 474632, 443760, 100160, 552267, 8173941, 211228, 107627, 510746, 174700, 171750, 268064, 128060, 215173, 186682, 289301, 86552, 96555, 159994, 161707, 234982, 154718, 238137, 97886, 95580, 218705, 107926, 109691, 134022, 103886, 518090, 155298, 123187, 253651, 175547, 91703, 102885, 89663, 105878, 270726, 174286, 109015, 179485, 182441, 142723, 99251, 165456, 131982, 91930, 218791, 83641, 103608, 105367, 265178, 100153, 109120, 152841]
lat = [57.14369, 53.55, 51.56844, 51.26249, 51.37795, 52.13459, 53.39337, 52.48142, 53.75, 53.81667, 53.58333, 50.72048, 53.79391, 50.82838, 51.45523, 52.2, 51.48, 51.73575, 51.9, 53.1905, 53.25, 51.88921, 52.40656, 51.11303, 54.52429, 52.92277, 53.52327, 56.5, 50.76871, 55.95206, 50.7236, 54.96209, 51.38914, 55.86515, 51.86568, 53.56539, 53.71667, 54.68611, 50.85519, 51.75369, 51.62907, 53.64904, 53.7446, 52.05917, 53.79648, 52.6386, 53.22683, 53.41058, 51.50853, 51.87967, 51.26667, 53.48095, 54.57623, 52.04172, 54.97328, 51.58774, 52.25, 52.62783, 52.9536, 52.52323, 53.54051, 51.75222, 52.57364, 50.37153, 50.71667, 50.79899, 53.76667, 51.58571, 51.45625, 53.61766, 53.43012, 53.42519, 53.48771, 53.38297, 51.50949, 52.41426, 50.90395, 51.53782, 53.64779, 53.45, 51.90224, 53.40979, 53.00415, 54.90465, 52.56667, 51.62079, 51.55797, 52.67659, 53.68331, 53.39254, 51.65531, 52.51868, 51.50853, 51.34603, 53.53333, 51.31903, 52.58547, 52.18935, 50.81448, 53.95763]
long = [-2.09814, -1.48333, 0.45782, -1.08708, -2.35907, -0.46632, -3.01479, -1.89983, -2.48333, -3.05, -2.43333, -1.8795, -1.75206, -0.13947, -2.59665, 0.11667, -3.18, 0.46958, -2.08333, -2.89189, -1.41667, 0.90421, -1.51217, -0.18312, -1.55039, -1.47663, -1.13691, -2.96667, 0.28453, -3.19648, -3.52751, -1.60168, 0.54863, -4.25763, -2.2431, -0.07553, -1.85, -1.2125, 0.57292, -0.47517, -0.74934, -1.78416, -0.33525, 1.15545, -1.54785, -1.13169, -0.53792, -2.97794, -0.12574, -0.41748, 0.51667, -2.23743, -1.23483, -0.75583, -1.61396, -2.99835, -0.88333, 1.29834, -1.15047, -1.46523, -2.1183, -1.25596, -0.24777, -4.14305, -2.0, -1.09125, -2.71667, 0.60459, -0.97113, -2.1552, -1.35678, -2.32443, -2.29042, -1.4659, -0.59541, -1.78094, -1.40428, 0.71433, -3.00648, -2.73333, -0.20256, -2.15761, -2.18538, -1.38222, -1.81667, -3.94323, -1.78116, -2.44926, -1.49768, -2.58024, -0.39602, -1.9945, -0.12574, -2.97665, -2.61667, -0.55893, -2.12296, -2.22001, -0.37126, -1.08271]
fig = plt.figure()
ax = Axes3D(fig)
X,Y,Z = np.array(long),np.array(lat),np.log10(np.array(pop))
colours = plt.cm.rainbow_r(Z/np.log10(max(pop)))
plot1 = ax.bar3d(X,Y,Z,dx=0.2,dy=0.2,dz=Z/3,color=colours)
ax.set_xlabel('\nLongitude (\u00B0)')
ax.set_ylabel('\nLatitude (\u00B0)')
ax.set_zlabel('\nlog\u2081\u2080(Population)')
ax.set_zlim3d(4,7)
ax.view_init(elev=70,azim=280)
colourMap = plt.cm.ScalarMappable(cmap=plt.cm.rainbow_r)
colourMap.set_array(Z)
colBar = plt.colorbar(colourMap).set_label('log\u2081\u2080(Population)')
plt.show()
The code produces this plot:
I think that the majority of the bars should be red/orange in colour, with only the major cities being yellow/green/blue...
(Z/np.log10(max(pop))).min() is 0.7. So all values are indeed in the upper range of the colormap.
You probably want to normalize your data before giving it to the colormap:
norm = plt.Normalize((Z/np.log10(max(pop))).min(), (Z/np.log10(max(pop))).max())
colours = plt.cm.rainbow_r(norm(Z/np.log10(max(pop))))
Related
How to plot pdf at the same graph as the histogram
I wrote a function to plot a histogram of the following data(shortened) data_1 = [0.68417915 0.53041328 0.05499373 0.32483917 0.30501979 0.12136537 0.22964997 0.5837272 0.06000122 0.69908738 0.15690346 0.20363323 0.10390346 0.98658757 0.98359924 0.29493355 0.72561782 0.75613625 0.69628136 0.71322217 0.63060554 0.91118187 0.14915375 0.70929528 0.42408604 0.35388851 0.62253336 0.63676291 0.44358184 0.45063505 0.36477958 0.15807182 0.714753 0.96713497 0.4094859 0.56495619 0.57509395 0.9355384 0.46284749 0.67779101 0.92363017 0.05682404 0.89631817 0.52587218 0.79428246 0.14486141 0.31300898 0.10176549 0.21841843 0.25688406 0.55415834 0.84957183 0.76246304 0.98489949 0.3936749 0.51460251 0.50138111 0.36060756 0.44854838 0.3919771 0.05113578 0.23980216 0.96111616 0.05969004 0.63652018 0.77869691 0.74565952 0.53789898 0.8876854 0.02370424 0.75647449 0.1494505 0.56362217 0.84942793 0.75265825 0.43319662 0.1012875 0.09946243 0.69463561 0.46931918 0.12913483 0.22142044 0.77253391 0.1691685 0.41114265 0.011321 0.41941435 0.28070956 0.65810948 0.58770776 0.68763623 0.36828773 0.70466821 0.8332811 0.12652526 0.16867114 0.59106388 0.56926637 0.87954323 0.62176163 7.35566843e-01 1.00146415e-01 6.68137620e-01 4.39246138e-01 3.75875260e-01 2.12544712e-02 3.68062161e-01 5.35692768e-01 6.50231419e-01 7.51573475e-01 1.43792206e-01 3.51057868e-01 1.77127799e-03 9.88480387e-01 8.73988015e-01 3.78791845e-01 5.89179323e-01 4.05978444e-01 6.88178816e-01 8.73515486e-01 3.66033185e-01 7.98291151e-01 2.30921252e-01 8.68201375e-04 4.92515713e-01 4.56100036e-01 5.66357689e-01 1.18801303e-01 8.15197293e-01 1.90998886e-02 4.91136435e-01 4.90613456e-01 1.31219088e-01 8.44170500e-01 1.72284226e-01 9.48296215e-01 7.36638954e-01 2.23674369e-01 7.46383520e-02 1.56815967e-01 6.14167905e-02 9.55175567e-01 1.74517808e-01 6.16529512e-01 7.02704931e-01 2.17204373e-01 6.78545848e-01 8.99756168e-01 5.28857712e-01 8.34009864e-01 5.87747412e-01 9.01901813e-02 9.94429960e-01 8.20847209e-01 3.88627889e-01 7.99302264e-01 1.19291073e-01 3.92748464e-01 4.84674232e-01 6.86047613e-01 9.09811416e-01 4.11619033e-01 5.22738580e-01 7.87679969e-01 8.31886542e-01 5.75564445e-01 7.03306890e-01 4.37121850e-01 2.17908948e-01 9.27734103e-01 1.69151398e-01 1.02815443e-01 8.86529746e-01 9.12471508e-01 3.62394360e-02 5.75760637e-01 9.02910130e-01 9.46808438e-01 5.22324825e-01 7.41599515e-02 1.67554744e-01 9.67044492e-01 6.41305316e-02 2.02375526e-01 7.87664750e-01 4.10928526e-01 3.75066800e-01 1.02825038e-01 7.99960722e-01 5.15931793e-01 6.07891990e-01 4.22650890e-01 2.50692729e-01 4.76696332e-01 3.42881458e-01 4.56350909e-01 2.21493003e-02 9.22045389e-01 4.31748031e-01 3.67451551e-01] And the following code def plot_histo(data_list, bin_count): plt.hist(data_list, bins=bin_count, density= True) return plt.show() plot_1 = plot_histo(data_1, 100) I also want to plot the pdf of this distribution on the same graph, but i don't really know how to do that since I'm new to python! Any tips?
There are several methods to estimate the pdf from the samples. One way is to use kernel density estimation, which can be done easily with sns.kdeplot. Another way is to fit parameters of a known distribution, e.g. with scikit-learn GaussianMixture if you have reasons to think your data is gaussian. import matplotlib.pyplot as plt import numpy as np import scipy.stats as stats import seaborn as sns from sklearn.mixture import GaussianMixture num_samples = 1_000 mu = 3.14 sigma = 1.27 data = np.random.randn(num_samples) * sigma + mu fig, ax = plt.subplots() # Histogram ax.hist(data, bins=10, density=True, label="Histogram") # Kernel Density Estimation (KDE) sns.kdeplot(data, bw_method=0.2, ax=ax, label="KDE") # Gaussian fitting gm = GaussianMixture(n_components=1).fit(data.reshape(-1, 1)) mu_ = gm.means_.item() sigma_ = gm.covariances_.item() xx = np.linspace(*ax.get_xlim(), num=100) plt.plot(xx, stats.norm.pdf(xx, mu_, sigma_), label="Gaussian") ax.legend() plt.show()
How can I create a 4D complex surface plot? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question I have the following Matlab code that I would like to be converted to a Python 3 one. r = (0:1:15)'; % create a matrix of complex inputs theta = pi*(-2:0.05:2); z = r*exp(1i*theta); %w = z.^(1/2) ; % calculate the complex outputs w = sqrt(r)*exp(1i*theta/2); figure('Name','Graphique complexe','units','normalized','outerposition',[ 0.08 0.1 0.8 0.55]); subplot(121) surf(real(z),imag(z),real(w),imag(w)) % visualize the complex function using surf xlabel('Real(z)') ylabel('Imag(z)') zlabel('Real(u)') cb = colorbar; colormap jet; % gradient from blue to red cb.Label.String = 'Imag(v)'; subplot(122) surf(real(z),imag(z),imag(w),real(w)) % visualize the complex function using surf xlabel('Real(z)') ylabel('Imag(z)') zlabel('Imag(v)') cb = colorbar; colormap jet; % gradient from blue to red cb.Label.String = 'Real(u)'; The results and original discussions can be found here. There's also a discussion available on this SO page. However, I failed to run and reproduce those codes. What can I try next?
This is perfectly straightforward if you spend the time learning how matplotlib (and 3d axes in particular) work: import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm from mpl_toolkits.mplot3d import Axes3D # compute data to plot r, theta = np.mgrid[1:16, -2*np.pi:2*np.pi:50j] z = r * np.exp(1j*theta) w = np.sqrt(r) * np.exp(1j*theta/2) # plot data fig = plt.figure() for plot_index in [1, 2]: if plot_index == 1: z_data, c_data = w.real, w.imag z_comp, c_comp = 'Re', 'Im' else: z_data, c_data = w.imag, w.real z_comp, c_comp = 'Im', 'Re' c_data = (c_data - c_data.min()) / c_data.ptp() colors = cm.viridis(c_data) ax = fig.add_subplot(f'12{plot_index}', projection='3d') surf = ax.plot_surface(z.real, z.imag, z_data, facecolors=colors, clim=[z_data.min(), z_data.max()]) ax.set_xlabel('$Re z$') ax.set_ylabel('$Im z$') ax.set_zlabel(f'${z_comp} w$') cb = plt.colorbar(surf, ax=ax) cb.set_label(f'${c_comp} w$') plt.show() The result: Some things that should be noted: Viridis colormap is good, jet is bad. In general there could be rendering issues with complex (interlocking) 3d geometries, because matplotlib has a 2d renderer. Fortunately, in this case the dataset is tightly coupled enough that this doesn't seem to happen, even if you rotate around the figure interactively. (But if you were to plot two intersecting surfaces together, things would probably be different.) One might want to enable latex rendering of labels to make the result extra crispy. The shading looks a lot better if you use the default option of colouring according to the z component of the data. If we also want to port the second part of my MATLAB answer you will have to use a trick to stitch together the two branches of the function (which, as I said, is necessary to render interlocking surfaces properly). For the specific example in the above code this will not give you perfect results, since both branches themselves contain discontinuities in the imaginary part, so regardless of our efforts in rendering the two surfaces nicely, the result will look a bit bad: import numpy as np import matplotlib.pyplot as plt import matplotlib.cm as cm from mpl_toolkits.mplot3d import Axes3D # compute data to plot r0 = 15 re, im = np.mgrid[-r0:r0:31j, -r0:r0:31j] z = re + 1j*im r, theta = abs(z), np.angle(z) w1 = np.sqrt(r) * np.exp(1j*theta/2) # first branch w2 = np.sqrt(r) * np.exp(1j*(theta + 2*np.pi)/2) # second branch # plot data fig = plt.figure() for plot_index in [1, 2]: # construct transparent bridge re_bridge = np.vstack([re[-1, :], re[0, :]]) im_bridge = np.vstack([im[-1, :], im[0, :]]) c_bridge = np.full(re_bridge.shape + (4,), [1, 1, 1, 0]) # 0% opacity re_surf = np.vstack([re, re_bridge, re]) im_surf = np.vstack([im, im_bridge, im]) w12 = np.array([w1, w2]) if plot_index == 1: z_comp, c_comp = 'Re', 'Im' z12, c12 = w12.real, w12.imag else: z_comp, c_comp = 'Im', 'Re' z12, c12 = w12.imag, w12.real color_arrays = cm.viridis((c12 - c12.min()) / c12.ptp()) z1,z2 = z12 c1,c2 = color_arrays z_bridge = np.vstack([z1[-1, :], z2[0, :]]) z_surf = np.vstack([z1, z_bridge, z2]) c_surf = np.vstack([c1, c_bridge, c2]) ax = fig.add_subplot(f'12{plot_index}', projection='3d') surf = ax.plot_surface(re_surf, im_surf, z_surf, facecolors=c_surf, clim=[c12.min(), c12.max()], rstride=1, cstride=1) ax.set_xlabel('$Re z$') ax.set_ylabel('$Im z$') ax.set_zlabel(f'${z_comp} w$') cb = plt.colorbar(surf, ax=ax) cb.set_label(f'${c_comp} w$') plt.show() The ugly jump in the right figure might be fixed with a lot of work, but it won't be easy: it's an actual discontinuity in both surface datasets occuring at negative real arguments. Since your actual problem is probably more like this, you will probably not need to face this issue, and you can use the above stitching (bridging) trick to combine your surfaces.
2d density contour plot with matplotlib
I'm attempting to plot my dataset, x and y (generated from a csv file via numpy.genfromtxt('/Users/.../somedata.csv', delimiter=',', unpack=True)) as a simple density plot. To ensure this is self containing I will define them here: x = [ 0.2933215 0.2336305 0.2898058 0.2563835 0.1539951 0.1790058 0.1957057 0.5048573 0.3302402 0.2896122 0.4154893 0.4948401 0.4688092 0.4404935 0.2901995 0.3793949 0.6343423 0.6786809 0.5126349 0.4326627 0.2318232 0.538646 0.1351541 0.2044524 0.3063099 0.2760263 0.1577156 0.2980986 0.2507897 0.1445099 0.2279241 0.4229934 0.1657194 0.321832 0.2290785 0.2676585 0.2478505 0.3810182 0.2535708 0.157562 0.1618909 0.2194217 0.1888698 0.2614876 0.1894155 0.4802076 0.1059326 0.3837571 0.3609228 0.2827142 0.2705508 0.6498625 0.2392224 0.1541462 0.4540277 0.1624592 0.160438 0.109423 0.146836 0.4896905 0.2052707 0.2668798 0.2506224 0.5041728 0.201774 0.14907 0.21835 0.1609169 0.1609169 0.205676 0.4500787 0.2504743 0.1906289 0.3447547 0.1223678 0.112275 0.2269951 0.1616036 0.1532181 0.1940938 0.1457424 0.1094261 0.1636615 0.1622345 0.705272 0.3158471 0.1416916 0.1290324 0.3139713 0.2422002 0.1593835 0.08493619 0.08358301 0.09691083 0.2580497 0.1805554 ] y = [ 1.395807 1.31553 1.333902 1.253527 1.292779 1.10401 1.42933 1.525589 1.274508 1.16183 1.403394 1.588711 1.346775 1.606438 1.296017 1.767366 1.460237 1.401834 1.172348 1.341594 1.3845 1.479691 1.484053 1.468544 1.405156 1.653604 1.648146 1.417261 1.311939 1.200763 1.647532 1.610222 1.355913 1.538724 1.319192 1.265142 1.494068 1.268721 1.411822 1.580606 1.622305 1.40986 1.529142 1.33644 1.37585 1.589704 1.563133 1.753167 1.382264 1.771445 1.425574 1.374936 1.147079 1.626975 1.351203 1.356176 1.534271 1.405485 1.266821 1.647927 1.28254 1.529214 1.586097 1.357731 1.530607 1.307063 1.432288 1.525117 1.525117 1.510123 1.653006 1.37388 1.247077 1.752948 1.396821 1.578571 1.546904 1.483029 1.441626 1.750374 1.498266 1.571477 1.659957 1.640285 1.599326 1.743292 1.225557 1.664379 1.787492 1.364079 1.53362 1.294213 1.831521 1.19443 1.726312 1.84324 ] Now, I have used many attempts to plot my contours using variations on: delta = 0.025 OII_OIII_sAGN_sorted = numpy.arange(numpy.min(OII_OIII_sAGN), numpy.max(OII_OIII_sAGN), delta) Dn4000_sAGN_sorted = numpy.arange(numpy.min(Dn4000_sAGN), numpy.max(Dn4000_sAGN), delta) OII_OIII_sAGN_X, Dn4000_sAGN_Y = np.meshgrid(OII_OIII_sAGN_sorted, Dn4000_sAGN_sorted) Z1 = matplotlib.mlab.bivariate_normal(OII_OIII_sAGN_X, Dn4000_sAGN_Y, 1.0, 1.0, 0.0, 0.0) Z2 = matplotlib.mlab.bivariate_normal(OII_OIII_sAGN_X, Dn4000_sAGN_Y, 0.5, 1.5, 1, 1) # difference of Gaussians Z = 0.2 * (Z2 - Z1) pyplot_middle.contour(OII_OIII_sAGN_X, Dn4000_sAGN_Y, Z, 12, colors='k') This doesn't seem to give the desired output.I have also tried: H, xedges, yedges = np.histogram2d(OII_OIII_sAGN,Dn4000_sAGN) extent = [xedges[0],xedges[-1],yedges[0],yedges[-1]] ax.contour(H, extent=extent) Not quite working as I wanted either. Essentially, I am looking for something similar to this: If anyone could help me with this I would be very grateful, either by suggesting a totally new method or modifying my existing code. Please also attach images of your output if you have some useful techniques or ideas.
seaborn does density plots right out of the box: import seaborn as sns import matplotlib.pyplot as plt sns.kdeplot(x, y) plt.show()
It seems that histogram2d takes some fiddling to plot the contour in the right place. I took the transpose of the histogram matrix and also took the mean values of the elements in xedges and yedges instead of just removing one from the end. from matplotlib import pyplot as plt import numpy as np fig = plt.figure() h, xedges, yedges = np.histogram2d(x, y, bins=9) xbins = xedges[:-1] + (xedges[1] - xedges[0]) / 2 ybins = yedges[:-1] + (yedges[1] - yedges[0]) / 2 h = h.T CS = plt.contour(xbins, ybins, h) plt.scatter(x, y) plt.show()
`map.scatter` on basemap not displaying markers
I have a map of Germany, and the coords of a few cities. plot displays the dots properly. I would like to use scatter instead, in order to be able to color the markets with respect to an other variable and then display a colorbar. The code runs in the console, but the dots are not visualized when I replace map.plot with map.scatter. from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np plt.figure(1) map = Basemap(projection='merc', resolution='l', llcrnrlat=44.0, llcrnrlon=5.0, urcrnrlat=57.0, urcrnrlon=17) map.drawcoastlines() map.drawcountries() map.fillcontinents(color='lightgray') map.drawmapboundary() long = np.array([ 13.404954, 11.581981, 9.993682, 8.682127, 6.960279, 6.773456, 9.182932, 12.373075, 13.737262, 11.07675 , 7.465298, 7.011555, 12.099147, 9.73201 , 7.628279, 8.801694, 10.52677 , 8.466039, 8.239761, 10.89779 , 8.403653, 8.532471, 7.098207, 7.216236, 9.987608, 7.626135, 11.627624, 6.852038, 10.686559, 8.047179, 8.247253, 6.083887, 7.588996, 9.953355, 10.122765]) lat = np.array([ 52.520007, 48.135125, 53.551085, 50.110922, 50.937531, 51.227741, 48.775846, 51.339695, 51.050409, 49.45203 , 51.513587, 51.455643, 54.092441, 52.375892, 51.36591 , 53.079296, 52.268874, 49.487459, 50.078218, 48.370545, 49.00689 , 52.030228, 50.73743 , 51.481845, 48.401082, 51.960665, 52.120533, 51.47512 , 53.865467, 52.279911, 49.992862, 50.775346, 50.356943, 49.791304, 54.323293]) colors = np.array([ 2.72189792, 3.62138986, 1.7947676 , 1.36524602, 1.75664228, 3.0777491 , 2.39580451, 1.17822874, 1.35503558, 2.28517658, 3.66472978, 1.76467741, 0.72551119, 1.76997962, 4.49420944, 2.34434288, 1.3243405 , 2.35945794, 3.16147488, 2.94025564, 1.68774158, 0.67602518, 1.60727613, 1.85608281, 3.57769226, 1.33501838, 3.32549868, 2.95492675, 2.83391381, 2.33983198, 2.59607424, 1.24260218, 1.89258818, 2.07508363, 3.03319927]) x, y = map(long, lat) map.plot(x,y,'o') plt.show()
try adding "zorder" so that the points show up above the map: map.fillcontinents(color='lightgray',zorder=0)
I also had the problem mentioned in the comment of the accepted answer (whole map becoming blue) so I ended up increasing the zorder of the plot instead : map.plot(x,y,'o',zorder=9999)
Separated caps in the errorbar plot
I am trying to make a plot with xerror and yerror, but for some of the points in my plot, the yerror caps are separated from the points. I don't know why it happens, any suggestion? My data: 9.25E-008 1.16E-009 9.47E-009 3.58E-010 1.68E-007 1.25E-009 9.37E-009 3.25E-010 1.95E-007 7.06E-010 1.36E-009 1.65E-010 7.49E-007 1.42E-009 1.27E-007 3.36E-010 1.38E-007 4.55E-010 5.54E-009 1.11E-010 9.93E-007 7.52E-009 6.62E-008 1.83E-009 1.31E-006 1.21E-008 3.13E-007 3.07E-009 1.14E-006 9.10E-009 7.73E-008 2.27E-009 2.04E-006 1.11E-008 6.91E-008 2.75E-009 1.10E-006 1.34E-008 1.26E-007 4.26E-009 1.75E-007 5.84E-009 2.90E-007 1.37E-009 9.32E-008 5.92E-009 4.29E-008 1.16E-009 2.96E-007 7.10E-009 1.23E-007 1.95E-009 8.27E-007 1.14E-008 8.67E-008 3.19E-009 7.11E-007 9.26E-009 5.17E-009 2.15E-009 1.00E-005 1.55E-008 3.55E-007 3.41E-009 1.78E-006 4.31E-009 5.71E-008 7.84E-010 5.45E-007 1.15E-008 1.03E-008 2.82E-009 2.06E-008 8.45E-009 5.26E-008 1.85E-009 6.88E-006 1.30E-008 6.02E-007 2.06E-009 8.32E-006 1.16E-008 8.26E-008 3.00E-009 1.45E-006 3.11E-009 2.02E-008 5.48E-010 2.89E-007 4.70E-009 1.13E-007 1.09E-009 1.92E-007 5.21E-009 5.60E-010 1.62E-009 7.78E-006 1.86E-008 1.71E-009 3.46E-009 5.41E-007 8.36E-009 1.07E-007 2.06E-009 2.40E-007 2.84E-009 3.29E-008 5.20E-010 5.37E-007 2.57E-008 2.19E-007 6.36E-009 2.71E-007 2.99E-008 2.71E-009 8.52E-009 3.48E-006 1.72E-008 7.01E-008 3.51E-009 My piece of code: import numpy as np import pylab as plt data=np.genfromtxt("Plot.txt",unpack=True).T fig = plt.figure() ax = fig.add_subplot(1,1,1) ax.errorbar(data[:,0],data[:,2],xerr=data[:,1],yerr=data[:,3], fmt= '.',color='red',capsize=5, elinewidth=1) ax.set_xscale('log') ax.set_yscale('log') plt.savefig("Plot.pdf") Thanks in advance!