matplotlib

matplotlib changes jpg image color

坚强是说给别人听的谎言 提交于 2021-01-27 22:14:37
问题 I'm reading images from filesystem using matplotlib imread function. However, it changes jpg image color when it displays those images. [Python 3.5, Anaconda3 4.3, matplotlib2.0] # reading 5 color images of size 32x32 imgs_path = 'test_images' test_imgs = np.empty((5,32,32,3), dtype=float) img_names = os.listdir('test_images'+'/') for i, img_name in enumerate(img_names): #reading in an image image = mpimg.imread(imgs_path+'/'+img_name) test_imgs[i] = image #Visualize new raw images plt.figure

Problem plotting an image's Fourier transforms. “ValueError: x and y can be no greater than 2-D, but have shapes (2592,) and (2592, 1, 3)”

谁说胖子不能爱 提交于 2021-01-27 21:12:56
问题 I'm trying to get the fft of an image and then plot the fraq of that fft with using matplotlib. However, this error message: "ValueError: x and y can be no greater than 2-D, but have shapes (2592,) and (2592, 1, 3)". I tried to reshape my np.array like so: import numpy as np from PIL import Image import matplotlib.pyplot as plt import tkinter from scipy.fftpack import fft, fft2, fftshift resim = Image.open(r'yeni.jpg') resim_data = np.asarray(resim) fourier = fft2(resim_data) #psd2D = np.abs

Merge countries using Cartopy

时光总嘲笑我的痴心妄想 提交于 2021-01-27 21:12:47
问题 I am using the following code to make a map for Sweden, Norway and Finland together as one area. however, I am struggling with it. I'm following this example, Python Mapping in Matplotlib Cartopy Color One Country. from shapely.geometry import Polygon from cartopy.io import shapereader import cartopy.io.img_tiles as cimgt import cartopy.crs as ccrs import geopandas import matplotlib.pyplot as plt def rect_from_bound(xmin, xmax, ymin, ymax): """Returns list of (x,y)'s for a rectangle""" xs =

matplotlib axesgrid - additional colorbar?

拟墨画扇 提交于 2021-01-27 21:12:22
问题 I want to add another colorbar to a plot where I use AxesGrid toolkit. For example, I add a colorbar axes using ImageGrid on the left, and then I add another one on the right manually. Here is a simple example: f = plt.figure(1) grid = ImageGrid(f, 111, # similar to subplot(111) nrows_ncols=(2, 2), axes_pad=0.01, add_all=True, cbar_location="left", label_mode='L', cbar_mode="edge", cbar_size="3%", cbar_pad="2%", ) for i in range(3): m = grid[i].matshow(np.arange(100).reshape((10, 10))) plt

Plot Markers on Curve where Value of X is known in matplotlib

此生再无相见时 提交于 2021-01-27 21:09:24
问题 I plotted a curve w.r.t time-series from the data which I got from an experiment. Data is collected at 10ms interval. Data is single row array. I also have calculated an array which contains the time at which a certain device is triggered. I drew axvlines of these triggered locations. Now I want to show markers where my curve crosses these axvlines. How can I do it? Time of trigger (X- is known). Curve is drawn but don't have any equation (irregular experiment data). Trigger interval is also

2x2 Contourf plots sharing the same colorbar

假装没事ソ 提交于 2021-01-27 20:56:09
问题 I would like to add a single color bar on the right side of the following 2x2 plot. import matplotlib.pyplot as plt import numpy as np x = np.linspace(-np.pi*2, np.pi*2, num=50) y = np.linspace(-np.pi*2, np.pi*2, num=50) def fun(x, y, pw1, pw2): X,Y = np.meshgrid(x, y) return (X, Y, np.cos(X*Y)**pw1 + np.sin(X+Y)**pw2) X, Y, f01 = fun(x,y,0,1) X, Y, f10 = fun(x,y,1,0) X, Y, f11 = fun(x,y,1,1) X, Y, f12 = fun(x,y,1,2) fig1, axs = plt.subplots(nrows=2,ncols=2, figsize=(8,8),sharex='col', sharey

Tkinter Matplotlib, backend conflict?

北慕城南 提交于 2021-01-27 20:30:27
问题 I'm quite new to python but I've spent my last week trying to code a software to visualize some weavy thingy. The basic cinematic is: the user enters every information needed into a GUI then click proceed and I have an other big function to genereate all the graphics. This was working but the problem was that when I ran the function, which lasts like 2 minutes, the tkinter window was freezing. I read that I should use threads. Then I found this: http://uucode.com/texts/pylongopgui/pyguiapp

Pandas Dataframe Plotting with uneven index values creates skewed graphs

梦想与她 提交于 2021-01-27 20:03:06
问题 I have a dataframe that consists of several experimental runs with different 'x-scales' to zero-in on a particular modelled behaviour, i.e. Exp1: xs = np.linspace(0.005,0.75,10) Exp2: xs = np.linspace(0.015,0.035,20) Combining these into a single dataframe for processing is as simple as a pd.concat but my difficulty is in plotting results. ax=v.plot( figsize=(10,13),kind='line', secondary_y='average_rx_delay', logy=True, title="Performance Comparison of Varying Packet Period Rates \n(counts

Can't set axis scale to logarithmic in 3D plot in matplotlib

喜你入骨 提交于 2021-01-27 20:01:13
问题 I would like to 3D plot the surface of a data 2d array with dimension [50,250]. Two of the axes ( x, z ) should be in logarithmic scale. Here's a MWE: import numpy as np xx = np.asanyarray([np.ones([250])*(m+1) for m in range(50)]) yy = np.asanyarray([range(250) for m in range(50)]) zz = np.asanyarray([np.sqrt(np.arange(250)*m) for m in range(50)]) import matplotlib.pyplot as plt from matplotlib import cm fig = plt.figure() ax = fig.gca(projection='3d') surf = ax.plot_surface(xx, yy, zz, cmap

How to color objects in an image with different color each

不羁的心 提交于 2021-01-27 19:45:13
问题 I'm having following problem: I have black/white images, which I have to colorize: Every white "blob" in the image represents an instance of an object and I want to color every object with a new color, but for every image i want to use the same color scheme: For example: 1st image: 3 Objects -> used colors: red, green, yellow 2nd image: 2 Objects -> used colors: red, green 3rd image: 5 objects -> used colors: red, green, yellow, pink, orange I've colored a couple of images by hand to show