matplotlib

Set matplotlib default figure window title

℡╲_俬逩灬. 提交于 2021-02-08 23:42:30
问题 The default window title of a figure is figure X, where X is increased each figure. I know how to change the title of a figure: fig = pylab.gcf() fig.canvas.set_window_title('Test') But how do I change the default window title (So that it will be Test 1, Test 2 etc..)? so that I will not need to change the window title each time. I did not find a key in the mpl.rcParams Thanks 回答1: When creating a figure using matplotlib.pyplot.subplots , there is an optional argument num that, even if not

Set matplotlib default figure window title

℡╲_俬逩灬. 提交于 2021-02-08 23:37:57
问题 The default window title of a figure is figure X, where X is increased each figure. I know how to change the title of a figure: fig = pylab.gcf() fig.canvas.set_window_title('Test') But how do I change the default window title (So that it will be Test 1, Test 2 etc..)? so that I will not need to change the window title each time. I did not find a key in the mpl.rcParams Thanks 回答1: When creating a figure using matplotlib.pyplot.subplots , there is an optional argument num that, even if not

Python: matplotlib plot inside QML layout

烈酒焚心 提交于 2021-02-08 16:39:11
问题 Consider the following python3 PyQt code to display an interactive matplotlib graph with toolbar import sys, sip import numpy as np from PyQt5 import QtGui, QtWidgets from PyQt5.Qt import * from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar import matplotlib.pyplot as plt app = QApplication(sys.argv) top = QWidget() fig = plt.figure() ax = fig.gca() x = np.linspace(0,5,100)

Python colorbar ticks are labeled with an offset of +1 and not with specifed values

梦想与她 提交于 2021-02-08 15:27:11
问题 I'm trying to do a contourf plot of the divergence of a vector field with python and then add a colorbar to this plot. My levels are intended to be symmetric around zero from -0.01 to 0.01. This is a part of my code: div_levs = [-0.01, -0.005, -0.0025, 0.0025, 0.005, 0.01] col = ['Blue', 'SteelBlue', 'White', 'Orange', 'Red'] c = plt.contourf(iwrf['x'], iwrf['y'], np.squeeze(iwrf['DIV'][ind_lev,:,:]), levels=div_levs, colors=col, extend='both') c.cmap.set_over('Magenta') c.cmap.set_under(

Draw Box-Plot with matplotlib

梦想与她 提交于 2021-02-08 13:47:21
问题 Is it possible to plot this kind of chart with matplotlib? 回答1: This looks a lot like a boxplot to me. I created a simple figure because colleagues often ask me about it when I am presenting my data like this If this is what you are looking for, the example code would be import matplotlib.pyplot as plt x1 = [-0.46,-1.25,-2.62,0.22] x2 = [0.24,1.88,-0.49,-0.73,-0.49] x3 = [-0.44,0.93,0.19,-4.36,-0.88] fig = plt.figure(figsize=(8,6)) plt.boxplot([x for x in [x1, x2, x3]], 0, 'rs', 1) plt.xticks

Seaborn: Specify an exact color

∥☆過路亽.° 提交于 2021-02-08 13:28:07
问题 You can specify a color for plots, but Seaborn will mute the color a bit during plotting. Is there a way to turn off this behavior? Example: import matplotlib import seaborn as sns import numpy as np # Create some data np.random.seed(0) x = np.random.randn(100) # Set the Seaborn style sns.set_style('white') # Specify a color for plotting current_palette = matplotlib.colors.hex2color('#86b92e') # Make a plot g = sns.distplot(x, color=current_palette) # Show what the color should look like sns

Spyder 4 is not displaying plots and displays message like this 'uncheck “Mute Inline Plotting” under the Plots pane options menu.'

孤者浪人 提交于 2021-02-08 13:27:30
问题 I wrote this code. It should display the plots in spyder ide. import pandas as pd import numpy as np import matplotlib.pyplot as plt from IPython.display import display from sklearn.ensemble import RandomForestRegressor from sklearn.metrics import mean_absolute_error import scipy.signal import scipy.stats from sklearn.model_selection import train_test_split train = pd.read_csv("train.csv", nrows=9000000,dtype={'acoustic_data':np.int16,'time_to_failure':np.float64}) train.rename({"acoustic

Why Z has to be 2-dimensional for 3d plotting in matplotlib

跟風遠走 提交于 2021-02-08 13:27:06
问题 I am trying to plot 3d Surface plots using code from this site using matplotlib: X,Y and Z are obtained as below: from math import pi from numpy import cos, meshgrid alpha = 0.7 phi_ext = 2 * pi * 0.5 def flux_qubit_potential(phi_m, phi_p): return 2 + alpha - 2 * cos(phi_p)*cos(phi_m) - alpha * cos(phi_ext - 2*phi_p) phi_m = linspace(0, 2*pi, 100) phi_p = linspace(0, 2*pi, 100) X,Y = meshgrid(phi_p, phi_m) Z = flux_qubit_potential(X, Y).T And 3d plotting is done with following code: from mpl

italic symbols in matplotlib?

本小妞迷上赌 提交于 2021-02-08 13:06:13
问题 I'm trying to get the gamma symbol to be italicised in a plot label but can't figure out how to do it? I thought this should work (but doesn't) plt.xlabel(r'$\mathit{\Gamma}$$^{*}$') I should add I am using the Helvetica font, so don't want to switch into tex mode, e.g. this doesn't work for me: import matplotlib import matplotlib.pyplot as plt plt.rcParams['font.family'] = "sans-serif" plt.rcParams['font.sans-serif'] = "Helvetica" plt.rcParams['text.usetex'] = True plt.plot(range(5), range(5

italic symbols in matplotlib?

孤人 提交于 2021-02-08 13:04:50
问题 I'm trying to get the gamma symbol to be italicised in a plot label but can't figure out how to do it? I thought this should work (but doesn't) plt.xlabel(r'$\mathit{\Gamma}$$^{*}$') I should add I am using the Helvetica font, so don't want to switch into tex mode, e.g. this doesn't work for me: import matplotlib import matplotlib.pyplot as plt plt.rcParams['font.family'] = "sans-serif" plt.rcParams['font.sans-serif'] = "Helvetica" plt.rcParams['text.usetex'] = True plt.plot(range(5), range(5