matplotlib

Python获取任意渐变色区段的16进制色值列表

不想你离开。 提交于 2021-02-06 10:41:59
背景 在玩转可视化的过程中,matplotlib及任意的其他可视化库,都有自己的cmap生成器,然而,有些时候,可能需要根据列表的长度预生成一组渐变色。 代码 def gen_colors(N): values = [int(i*250/N) for i in range(N)] # print(values) colors=["#%02x%02x%02x"%(200,int(g),40)for g in values] # 250 250 250 ,g值越小越靠近0红色 return colors colors = gen_colors(df['2020年'].shape[0]) colors 在Bokeh中进行渲染测试: x = y = [i for i in range(21)] p=figure() p.scatter(x,y,radius=0.2, fill_color=colors, fill_alpha=1.0, line_color=None ) show(p) 如果你想要其他色盘中的某一端色值: from PIL import Image # 16进制颜色格式颜色转换为RGB格式 def Hex_to_RGB(hex): r = int(hex[1:3],16) g = int(hex[3:5],16) b = int(hex[5:7], 16) return r

How do I omit matplotlib printed output in Python / Jupyter notebook? [duplicate]

岁酱吖の 提交于 2021-02-06 10:14:53
问题 This question already has answers here : How to hide <matplotlib.lines.Line2D> in IPython notebook (2 answers) Closed 3 years ago . When I make a simple plot inside an IPython / Jupyter notebook, there is printed output, presumably generated from matplotlib standard output. For example, if I run the simple script below, the notebook will print a line like: <matplotlib.text.Text at 0x115ae9850> . import random import pandas as pd %matplotlib inline A = [random.gauss(10, 5) for i in range(20) ]

How do I omit matplotlib printed output in Python / Jupyter notebook? [duplicate]

ε祈祈猫儿з 提交于 2021-02-06 10:14:36
问题 This question already has answers here : How to hide <matplotlib.lines.Line2D> in IPython notebook (2 answers) Closed 3 years ago . When I make a simple plot inside an IPython / Jupyter notebook, there is printed output, presumably generated from matplotlib standard output. For example, if I run the simple script below, the notebook will print a line like: <matplotlib.text.Text at 0x115ae9850> . import random import pandas as pd %matplotlib inline A = [random.gauss(10, 5) for i in range(20) ]

How does Python's matplotlib.pyplot.quiver exactly work?

谁说我不能喝 提交于 2021-02-06 09:57:08
问题 I'm trying to understand how the quiver function in the NumPy module works. Supposedly it allows to visualize graphically the values of two arrays, for example horizontal and vertical velocities. I have the following very simple example, but I show it just to see if you can help me to find out what I'm not doing well: x = np.linspace(0,1,11) y = np.linspace(1,0,11) u = v = np.zeros((11,11)) u[5,5] = 0.2 plt.quiver(x, y, u, v) The code produces the following figure: As you can see, the arrow

mathplotlib imshow complex 2D array

心不动则不痛 提交于 2021-02-06 08:55:26
问题 Is there any good way how to plot 2D array of complex numbers as image in mathplotlib ? It makes very much sense to map magnitude of complex number as "brightness" or "saturation" and phase as "Hue" ( anyway Hue is nothing else than phase in RBG color space). http://en.wikipedia.org/wiki/HSL_and_HSV But as far as I know imshow does accept only scalar values which are then mapped using some colorscale. There is nothing like ploting real RGB pictures? I thing it would be easy just implement a

mathplotlib imshow complex 2D array

自闭症网瘾萝莉.ら 提交于 2021-02-06 08:53:56
问题 Is there any good way how to plot 2D array of complex numbers as image in mathplotlib ? It makes very much sense to map magnitude of complex number as "brightness" or "saturation" and phase as "Hue" ( anyway Hue is nothing else than phase in RBG color space). http://en.wikipedia.org/wiki/HSL_and_HSV But as far as I know imshow does accept only scalar values which are then mapped using some colorscale. There is nothing like ploting real RGB pictures? I thing it would be easy just implement a

Display multiple mpld3 exports on a single HTML page

半城伤御伤魂 提交于 2021-02-05 20:30:40
问题 I've found the mpld3 package to be brilliant for exporting a matplolib plot to HTML and displaying this via a flask app. Each export comes with a lot of JS which seems unnecessary duplication if you want to display multiple plots within a single page. However I'm not well enough versed in JS to extract the relevant components and then loop through them. The .fig_to_dict method gives the necessary JSON to display each chart but then I'm left wondering what JS/ template work is needed to

3D plot with Matplotlib

て烟熏妆下的殇ゞ 提交于 2021-02-05 20:10:48
问题 I'm simply trying to plot a surface and its contour in 3D, exactly as in this example. This is the code I'm using to do it: import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import axes3d from matplotlib import cm import numpy def plot_3d_contour(x_dim, y_dim, x_steps, y_steps, scalar_field, file_path): fig = plt.figure() x, y = numpy.mgrid[-x_dim/2:x_dim/2:x_steps*1j, -y_dim/2:y_dim/2:y_steps*1j] v_min = numpy.min(scalar_field) v_max = nupmy.max(scalar_field) ax = fig.gca(projection=

3D plot with Matplotlib

偶尔善良 提交于 2021-02-05 20:01:30
问题 I'm simply trying to plot a surface and its contour in 3D, exactly as in this example. This is the code I'm using to do it: import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import axes3d from matplotlib import cm import numpy def plot_3d_contour(x_dim, y_dim, x_steps, y_steps, scalar_field, file_path): fig = plt.figure() x, y = numpy.mgrid[-x_dim/2:x_dim/2:x_steps*1j, -y_dim/2:y_dim/2:y_steps*1j] v_min = numpy.min(scalar_field) v_max = nupmy.max(scalar_field) ax = fig.gca(projection=

3D plot with Matplotlib

霸气de小男生 提交于 2021-02-05 19:59:11
问题 I'm simply trying to plot a surface and its contour in 3D, exactly as in this example. This is the code I'm using to do it: import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import axes3d from matplotlib import cm import numpy def plot_3d_contour(x_dim, y_dim, x_steps, y_steps, scalar_field, file_path): fig = plt.figure() x, y = numpy.mgrid[-x_dim/2:x_dim/2:x_steps*1j, -y_dim/2:y_dim/2:y_steps*1j] v_min = numpy.min(scalar_field) v_max = nupmy.max(scalar_field) ax = fig.gca(projection=