matplotlib

How to display ticks in plain number for seaborn heatmap with logarithmic scale?

被刻印的时光 ゝ 提交于 2021-02-11 14:41:20
问题 I am generating a heatmap using seaborn which has a logarithmic scale. How can I change the colorbar labels from scientific notation to plain number. import math from matplotlib.colors import LogNorm vmax=2 vmin=0.5 center = (vmax+vmin)/2 log_norm = LogNorm(vmin=vmin, vmax=vmin) cbar_ticks = [0.5, 0.66, 1, 1.5, 2] ax = sns.heatmap(corr, square=True, mask=mask, cmap=cmap_type, linewidths=.5, vmax=vmax, vmin=vmin, norm=log_norm, cbar_kws={"ticks": cbar_ticks}, center=center) Edit: The following

Matplotlib Colorbar Ticks Mathtext Format

浪子不回头ぞ 提交于 2021-02-11 14:37:49
问题 The title is self explanatory, could not find how to implement it. For the axis ticks format similar command looks like this: ax.ticklabel_format(useMathText=True) , there is no problem with this one, it works. But for the colorbar's ticks to make them appear in the MathText format I could not find how to implement it. I have tried to pass the useMathText=True as an arg into the cbar.ax.tick_params() and cbar = plt.colorbar() but that did not work. to recreate: import numpy as np import

Increase dpi in matplotlib chart without changing it's size

筅森魡賤 提交于 2021-02-11 14:31:51
问题 I'm trying to create a pdf using Python's reportlab module. I generated a png with matplotlib and saved it in the pdf file using report labs canvas.drawImage method. My problem is that the generated png file is very fuzzy. I specified the size in inches with plt.figure(figsize=(20,10)) and saved the picture with the plt.savefig method. This works out perfectly (except the fuzzy quality of the picture). But when I increase the dpi within the savefig method the size of the picture increases. Is

How to make items clickable (onpick) in Seaborn scatterplot?

不打扰是莪最后的温柔 提交于 2021-02-11 14:26:40
问题 I'm using sns.scatterplot function to analyze some data. It would be very helpful for me if I could pick an object on the plot by clicking on it and execute a function. Matplotlib has onpick event which does the trick, but I couldn't find how could I do the same with Seaborn. It is using Matplotlib internally, so I think that it is possible somehow to attach onpick handler to it. The reason I'm using Seaborn instead of basic Matplotlib plot is that I need hue parameter. Here is basically the

How to extract the boundary values from k-nearest neighbors predict

点点圈 提交于 2021-02-11 14:24:30
问题 How can only the boundary values be extracted , or returned, from .predict , for sklearn.neighbors.KNeighborsClassifier()? MRE import pandas as pd import numpy as np from sklearn.datasets import load_iris from sklearn.neighbors import KNeighborsClassifier import seaborn as sns import matplotlib.pyplot as plt from matplotlib.colors import ListedColormap # prepare data iris = load_iris() X = iris.data y = iris.target df = pd.DataFrame(X, columns=iris.feature_names) df['label'] = y species_map =

Matplotlib zoom level stepping back on key press event

谁说胖子不能爱 提交于 2021-02-11 14:24:08
问题 I want to choose a zone in my matplotlib figure by zooming into the figure then, when the key 'c' is pressed, getting the current axes limits. However, on key press event, the figure automatically rolls back the zoom level one step back. So when the callback function is called, it gets the axes limit for the previous zoom level (ie, "home" limits if I have zoomed only once, or the second-to-last zoom level if I have zoomed more than once). I thought maybe getting the axes limits interferes

tight savefig without axes in matplotlib

核能气质少年 提交于 2021-02-11 14:11:05
问题 When using a matplotlib to draw something without axes, savefig() isn't truly "tight": import matplotlib.pyplot as plt circ = plt.Circle((0, 0), 1.0) plt.gca().add_artist(circ) plt.gca().set_aspect("equal") plt.axis("off") # plt.show() plt.savefig("out.svg", bbox_inches="tight") That's because the SVG contains the hidden "background patch" <g id="patch_1"> <path d="M 0 280.512 L 280.512 280.512 L 280.512 0 L 0 0 z " style="fill:none;"/> </g> How to remove it? 回答1: pad_inches option! plt

Connecting dots in a 2D scatterplot with a color as a third dimension

百般思念 提交于 2021-02-11 14:02:40
问题 Let's say I have the following dataset: x = np.arange(150000,550000,100000) y = np.random.rand(7*4) z = [0.6,0.6,0.6,0.6,0.7,0.7,0.7,0.7,0.8,0.8,0.8,0.8,0.9,0.9,0.9,0.9,1.0,1.0,1.0,1.0,1.1,1.1,1.1,1.1,1.2,1.2,1.2,1.2] x_ = np.hstack([x,x,x,x,x,x,x]) and I am doing a scatter plot: plt.figure() plt.scatter(x_,y,c=z) plt.colorbar() plt.set_cmap('jet') plt.xlim(100000,500000) plt.show() However, I would like to connect the dots of the same color. I tried just using plt.plot with the same

Matplotlib Quiver plot matching key label color with arrow color

此生再无相见时 提交于 2021-02-11 13:47:47
问题 Using matplotlib, python3.6. I am trying to create some quiverkeys for a quiver plot but having a hard time getting the label colors to match certain arrows. Below is a simplified version of the code to show the issue. When I use the same color (0.3, 0.1, 0.2, 1.0 ) for a vector at (1,1) and as 'labelcolor' of a quiverkey I see 2 different colors. q=plt.quiver([1, 2,], [1, 1], [[49],[49]], [0], [[(0.6, 0.8, 0.5, 1.0 )], [(0.3, 0.1, 0.2, 1.0 )]], angles=[[45],[90]]) plt.quiverkey(q, .5, .5, 7,

Error involving Tkinter/matplotlib “no display name and no $DISPLAY environment variable” on CentOS

ぃ、小莉子 提交于 2021-02-11 13:46:37
问题 Most relevant questions I've seen here are not fixing my issue. I'm writing a program that uses matplotlib and tkinter to make a GUI. I'm running CentOS7. I get this when trying to run python36 testGraph.py on my server: Traceback (most recent call last): File "testGraph.py", line 167, in <module> app = SeaofBTCapp() File "testGraph.py", line 57, in __init__ tk.Tk.__init__(self, *args, **kwargs) File "/usr/lib64/python3.6/tkinter/__init__.py", line 2020, in __init__ self.tk = _tkinter.create