matplotlib

How define a boundary in matplotlib python?

二次信任 提交于 2021-02-07 07:17:58
问题 I want to plot the following field equations: dx/dt = x*(4*y+3*x-3) dy/dt = y*(4*y+3*x-4) but I do not know how can I restrict the boundary to a triangle: x>=0, y>=0, x<=1-y : # stream plot with matplotlib import numpy as np import matplotlib.pyplot as plt def velocity_i(x,y): vx = x*(3*x+4*y-3) vy = y*(3*x+4*y-4) return vx, vy n=100 x = np.linspace(0, 1, n) y = np.linspace(0, 1, n) X, Y = np.meshgrid(x, y) Ux, Uy = velocity_i(X, Y) vels = (Ux**2+Uy**2)**0.5 plt.figure(figsize=(5,4)) stream =

Different precision on matplotlib axis

旧城冷巷雨未停 提交于 2021-02-07 07:14:51
问题 My teacher said that in a graph I must label the axis like 0, 0.25, 0.5 not 0.00,0.25,0.50,... . I know how to label it like 0.00,0.25,0.50 ( plt.yticks(np.arange(-1.5,1.5,.25)) ), however, I don't know how to plot the ticklabels with different precision. I've tried to do it like plt.yticks(np.arange(-2,2,1)) plt.yticks(np.arange(-2.25,2.25,1)) plt.yticks(np.arange(-1.5,2.5,1)) without avail. 回答1: This was already answered, for example here Matplotlib: Specify format of floats for tick lables

Different precision on matplotlib axis

懵懂的女人 提交于 2021-02-07 07:14:20
问题 My teacher said that in a graph I must label the axis like 0, 0.25, 0.5 not 0.00,0.25,0.50,... . I know how to label it like 0.00,0.25,0.50 ( plt.yticks(np.arange(-1.5,1.5,.25)) ), however, I don't know how to plot the ticklabels with different precision. I've tried to do it like plt.yticks(np.arange(-2,2,1)) plt.yticks(np.arange(-2.25,2.25,1)) plt.yticks(np.arange(-1.5,2.5,1)) without avail. 回答1: This was already answered, for example here Matplotlib: Specify format of floats for tick lables

Different precision on matplotlib axis

若如初见. 提交于 2021-02-07 07:12:06
问题 My teacher said that in a graph I must label the axis like 0, 0.25, 0.5 not 0.00,0.25,0.50,... . I know how to label it like 0.00,0.25,0.50 ( plt.yticks(np.arange(-1.5,1.5,.25)) ), however, I don't know how to plot the ticklabels with different precision. I've tried to do it like plt.yticks(np.arange(-2,2,1)) plt.yticks(np.arange(-2.25,2.25,1)) plt.yticks(np.arange(-1.5,2.5,1)) without avail. 回答1: This was already answered, for example here Matplotlib: Specify format of floats for tick lables

matplotlib: How to pick up shift click on figure?

岁酱吖の 提交于 2021-02-07 06:57:16
问题 I have a matplotlib and I have created a button_press_event like this: self.fig.canvas.mpl_connect('button_press_event', self.onClick) def onClick(self, event) if event.button == 1: # draw some artists on left click elif event.button == 2: # draw a vertical line on the mouse x location on wheel click elif event.button == 3: # clear artists on right click Now is it possible to modify the wheel click handler to something like this elif event.button == 2 or (event.button == 1 and event.key ==

Passing datetime-like object to seaborn.lmplot

狂风中的少年 提交于 2021-02-07 06:51:17
问题 I am trying to do a plot of values over time using seaborn linear model plot but I get the error TypeError: invalid type promotion I have read that it is not possible to plot pandas date objects, but that seems really strange given seaborn requires you pass a pandas DataFrame to the plots. Below is a simple example. Does anyone know how I can get this to work? import pandas as pd import seaborn as sns; sns.set(color_codes=True) import matplotlib.pyplot as plt date = ['1975-12-03','2008-08-20'

Interaction between networkx and matplotlib

时光总嘲笑我的痴心妄想 提交于 2021-02-07 06:24:47
问题 I am trying networkx and visualization in matplotlib an I'm confused becouse I do not clearly understand how do they interact with each other? There simple example import matplotlib.pyplot import networkx as nx G=nx.path_graph(8) nx.draw(G) matplotlib.pyplot.show() Where do I tell pyplot, that I want to draw graph G? I guess that nx.draw use something like matplotlib.pyplot.{plot, etc ...} So, if I want to draw 2 graphs: import matplotlib.pyplot import networkx as nx G=nx.path_graph(8) E=nx

Custom Matplotlib projection: Schmidt projection

爱⌒轻易说出口 提交于 2021-02-07 04:30:17
问题 I am trying to modify this custom-projection example: http://matplotlib.org/examples/api/custom_projection_example.html to display a Schmidt plot. The mathematics behind the projection are explained e.g. here: https://bearspace.baylor.edu/Vince_Cronin/www/StructGeol/StructLabBk3.html I made some modifications of the example which brought me closer to the solution but I am still doing something wrong. Anything I change within the function transform_non_affine makes the plot look worse. It

Custom Matplotlib projection: Schmidt projection

荒凉一梦 提交于 2021-02-07 04:30:05
问题 I am trying to modify this custom-projection example: http://matplotlib.org/examples/api/custom_projection_example.html to display a Schmidt plot. The mathematics behind the projection are explained e.g. here: https://bearspace.baylor.edu/Vince_Cronin/www/StructGeol/StructLabBk3.html I made some modifications of the example which brought me closer to the solution but I am still doing something wrong. Anything I change within the function transform_non_affine makes the plot look worse. It

Matplotlib imshow() too many objects for cmap

时光毁灭记忆、已成空白 提交于 2021-02-07 04:22:09
问题 I'm trying to create a simple imshow() plot (matplotlib v.1.2.1) of a 2D gaussian function: import matplotlib.pyplot as plt import numpy as np from pylab import * def gaussian(x,y,stdx,stdy): return 1.0/(2*np.pi*stdx*stdy) * (np.exp(-0.5*(x**2/stdx**2 + y**2/stdy**2))) coords = np.linspace(-1,1,100) X,Y = np.meshgrid(coords,coords) std_list = np.linspace(1,2,20) output = [gaussian(X,Y,std_list[i],std_list[i]) for i in range(len(std_list))] for i in range(len(output)): plt.imshow(X,Y,np.array