72,837 questions
1
vote
1
answer
50
views
Python Matplotlib: Animation does not update plot alongside series of images
I am trying to create an animation of two plots side by side on which on the first plot I display a series of images and on the second plot a log log representation of data corresponding the image ...
6
votes
0
answers
77
views
matplotlib axes3d how to use all window space plotting
I have an application in python that embeds a matplotlib.Axes3d in a QWidget to draw 3D curves.
The problem is that when resizing or there is a lot of space in the window, matplotlib cuts the plot ...
0
votes
1
answer
52
views
Matplotlib update AnnotationBBox position
I'm trying to display labels in a 3D plot. My final goal is to display a tiny version of an image/texture at the coordinates of its average color in Lab space.
After multiple failed attempts, I ...
1
vote
1
answer
34
views
"AttributeError: 'FigureCanvasInterAgg' object has no attribute 'tostring_rgb'" in pyplot.show()
While using the following code:
from matplotlib import pyplot
from sarpy.visualization.remap import Density
from sarpy.io.product.converter import open_product
from sarpy.io.complex.converter import ...
0
votes
1
answer
68
views
Locate where a map boundary is in the world with my created shapefile
I made a shapefile containing the boundaries of all the worlds countries and some of their regions (like the states in the US, Canadian provinces, etc). I've been trying to set a boundary box of my ...
4
votes
1
answer
82
views
How to create a class that generates auto-updateable plots
I want to create a class that will create updateable plots. I plan on having 8-16 figures in one window, so it would be nice to have a class that would initiate these for me. These graphs will auto-...
-3
votes
0
answers
49
views
Creating a figure with matplotlib imshow with native resolution of the array [duplicate]
I am currently creating figures with one or more imshow plots.
I would like to get a native plot of one of those imshow plots.
To my understanding I would need to calculate the figure size, with ...
2
votes
1
answer
32
views
Matplotlib plot window does not stay minimized
I am creating a dashboard using matplotlib. The following is my python3 code. When I minimize the matplotlib plot window, the window jumps back up and the window does not stay minimized. What should I ...
-2
votes
0
answers
29
views
How do I add a legend to for pixmapped image [duplicate]
I have a 2D array of integer data that I am plotting with matplotlib's axes interface (not the pyplot interface). When I use ax.imshow I get the plot I am looking for. The built in colorizer handles ...
1
vote
1
answer
51
views
python Plot Swaps Colours in Subplot — How to make one colour stick to one data set?
I am trying to plot some data from a Markov Chain Monte Carlo run, using getDist, which (I assume) uses matplotlib under the hood for plotting. There is no error message or anything, and it produces a ...
Best practices
2
votes
4
replies
55
views
Visualizing categorical features with severe Class Imbalance for ML: Absolute Counts vs Normalized Percentages?
I am performing Exploratory Data Analysis (EDA) on a medical dataset (Primary Biliary Cirrhosis) to select features for a multiclass classification model. My target variable is Stage (1, 2, 3, 4).
The ...
Tooling
0
votes
3
replies
47
views
How to better emulate this broken line plot with matplotlib or seaborn?
What I want to achieve is something as below:
I have found the brokenaxes package here, and tried it:
from brokenaxes import brokenaxes
import numpy as np
bax = brokenaxes(xlims=((0, 10), (195, 200))...
1
vote
1
answer
69
views
how to carryon after matplotlib has been called
I am stuck after displaying using matplotlib because I can not seem to figure out what code to use to continue after using matplotlib. Specifically, I use:
plt.figure(figsize=[10, 10])
plt.title(&...
1
vote
1
answer
118
views
Jupyter Lite outputs a blank file when I use plt.savefig()
I'm writing a Python code that's supposed to create a graph and export it as a vector PDF file. I'm using Jupyter Lite at jupyter.org.
I've successfully created the graph, but when I try to export it ...
1
vote
2
answers
88
views
Why does Matplotlib DatetimeIndex plot misalign dates?
Why does matplotlib round to the nearest month sometimes and not other times depending on the order lines are plotted and which dates are used. ax3 and ax4 are particularly interesting because they ...
1
vote
1
answer
52
views
Colorbar tick locations not correct
I'm making a protein secondary structure plot, at first with trivial data:
import matplotlib.pyplot as plt
fig, ax0 = plt.subplots(1,1, layout = "constrained")
from matplotlib.colors import ...
0
votes
1
answer
74
views
Show the value at hovered position (x,y) with interactive pcolormesh plots
I find the coordinates shown below (in the form: (x, y) [z]) very useful for interacting with the data. Unfortunately, librosa.display.specshow does not show the value at (x, y), rather, only the ...
2
votes
1
answer
111
views
Why is list[list[str]] not equal to list[HashableList[Hashable]]
I struggle with typechecks using matplotlib.pyplot.subplot_mosaic.
I have create the following fuction, which generates the mosaic pattern and the per_subplot_kw:
def create_mosaic(num_rows):
def ...
Advice
0
votes
2
replies
58
views
How do I set the matplotlib co-ordinate system to SVG
A synopsis of my code.
import matplotlib.pyplot as plt
import shapely.plotting
from shapely.geometry import Polygon
facing = 'north'
shape = 'triangle'
polygon = Polygon(((1, 17), (9, 1), (17,...
0
votes
1
answer
58
views
Crop extra white-space on matplotlib picture
I made a "gauge" image using the following code:
taux = 91
# Plot
fig, ax = plt.subplots(figsize=(7.5,5), subplot_kw=dict(polar=True))
ax.set_theta_zero_location("W") ...
1
vote
1
answer
87
views
How to expand equal-aspect data limits in one direction only?
I've been trying to set equal data aspect ratios in matplotlib with ax.set_aspect('equal', 'datalim') (aka ax.axis('equal')), while preserving lower bounds/limits, aka anchoring one side of the data ...
4
votes
1
answer
118
views
Tick direction of 3D plot in Matplotlib
In Matplolib, it is possible to change the direction of the tick of 2D plots with tick_params parameters
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
fig ...
2
votes
2
answers
177
views
Plotting Y data vs X data with alternating colors for each section in Python
I have what might be a simple problem.
I have a dataset that looks like this:
Exp Site Hole Core Type Sect A/W ... Instrument Instrument group Text ID Test No. Sample ...
1
vote
1
answer
62
views
How to limit the number of displayed xticks in pyplot when x values are strings
I have a scatterplot in pyplot where the x-values are necessarily strings. Is there an easy way to limit the number of xticklabels that pyplot will show?
I am not referring to specifying the xticks ...
2
votes
1
answer
72
views
Matplotlib's ax.fill_between() function not working for 3D plots
I'm doing some data visualisation for an experiment on near/far field diffraction.
My goal is to essentially put several 2d plots in front of one another, pretty much identical to how this example in ...
-1
votes
1
answer
74
views
Saving matplotlib figures when running multiple subsequent python files via a .bat file on Windows
SET UP
I have multiple scripts that I execute with a .bat file, like so:
cd C:\\path\\to\\my\\project\\directory
echo Running script 1
"C:\\ProgramData\\miniforge3\\envs\\myenv\\python.exe" ...
0
votes
1
answer
101
views
Why different files produce same GNSS plots in my Python code?
I wrote a piece of Python code to read different GPS observation files (.24o) and navigation files (.24p), and generate polar plots of satellite trajectories. The goal is that the RINEX file can be ...
3
votes
1
answer
134
views
Matplotlib LaTeX text not respecting font family
I am trying to display a LaTeX-style equation in a Matplotlib plot using a custom font (Algerian). I want both the equation and the surrounding text to use the same upright (non-italic) font. Using ...
2
votes
1
answer
143
views
How do I make a matplotlib bar graph scale with the amount of items?
I am working on a small project and it is my first time using matplotlib, and I am struggling with how to make my bar graph look better with more inputs. The whole idea of the program is to read text ...
Advice
0
votes
2
replies
126
views
Analysis of a tapering function
On Window function - Wikipedia tapering functions are plotted using two different styles. One shows curve (samples) and the other Fourier transform (bins).
I've prepared two tapering functions based ...
2
votes
1
answer
108
views
How to connect a callback to "Reset original view" event in Matplotlib?
I would like to connect onTool() callback to "Reset original view" event, i.e. clicking on "home" icon in the bottom left corner of Matplotlib figure. I tried several options ...
3
votes
1
answer
84
views
Why the initial figure dimensions are wrong in this matplotlib script?
This Python 3.13 script with Matplotlib 3.10.3 run on 1200x1600 display:
import matplotlib.pyplot as plt, numpy as np
fig, ax = plt.subplots()
plt.tight_layout(pad=0.01)
fig.canvas.manager....
3
votes
1
answer
120
views
rasterized, dpi, bbox_inches='tight' and axins mess up the plot in a pdf
When I run the code below, the plot in the PDF is messed up. The content of the plot and the colorbar are shifted down to the left, as shown in the attached screenshot of the PDF.
import matplotlib....
0
votes
0
answers
77
views
Rendering matplotlib figure in VSCode (Jupyter) like fig.savefig
Problem
When saving a matplotlib figure using fig.savefig(), the figure looks different from when the figure is rendered in a Jupyter Notebook.
Question
How can I render a static (non-interactive) ...
1
vote
1
answer
66
views
Boxplot with scatter points: preventing overlap when categories are similar
I am trying to create a boxplot with different categories and overlay scatter points on top of it. The problem I am encountering is that when the results across categories are very similar, the ...
3
votes
2
answers
113
views
How to ensure cartopy features are rendered after setting matplotlib Axes box aspect?
I have a function that will produce a map when given a DataFrame containing lat/lon coordinates. Regardless of the shape of the track that can be drawn from coodinate pairs and timestamps, I want to ...
0
votes
1
answer
50
views
Multiple CDFS on the same plot with specified ranges
I was trying to do something for a project where I create two random 3D vectors, project them onto a 2D plane by removing their x-component, taking the dot product between the two to find their ...
0
votes
0
answers
62
views
Coarsening the resolution of a xarray dataset
Very new to python! I am trying to model bottom water temperatures over time and need to reduce the resolution of my model from 1/20º to 1º. My ultimate goal is to map this and select specific grid ...
1
vote
1
answer
111
views
Specify hue when having multiple vertical plots in same graphic
I use a swarmplot to display vertically multiple distributions in the same graphic:
df = polars.read_csv("...")
ax = seaborn.swarmplot(data=[df["ColA"], df["ColB"], df[&...
Advice
0
votes
2
replies
121
views
How to retrieve a figure title from a Figure or FigureCanvas?
I'm using python and PySide6 to build GUI desktop apps.
In my code I generate a list of figures, and then pass them to my view to display each in a separate tab. Right now, I loop through the list, ...
1
vote
1
answer
140
views
Tkinter window shrinks after embedding Matplotlib canvas — how to prevent it?
I'm building a multi-frame Tkinter app for a school project (NEA dashboard). One of the frames displays a Matplotlib scatter plot using FigureCanvasTkAgg. The issue is that after switching to the ...
Advice
0
votes
3
replies
124
views
How to adjust vector length in quiver plot?
This is the program I am using:
fig, ax = plt.subplots(figsize=(4, 4))
t, dt = np.linspace(-4, 4, 10, retstep=True)
x = t
y = t**3 - 9*t
xy = np.stack((x, y), axis=1)
n = len(xy)
d1ydx1 = np....
1
vote
0
answers
166
views
Jupyter notebook refusing to recognize matplotlib installation
I am running a Jupyter notebook and I had to manually install using pip Matplotlib 3.10.7 because it wasn't recognized on my Anaconda. Now when I try to get it in Jupyter I get this error:
...
0
votes
0
answers
103
views
Shrinking colorbar for geopandas
I am attempting to shrink the colorbar for my map generated with geopandas as the default one generated is too huge.
I have tried using fig.colorbar(kioskplot, ax=ax, shrink=0.7) but python is giving ...
2
votes
2
answers
125
views
getting a tensor of shape (32,) instead of a single value as a label
when i try to print/plt.tile the label of an image, its printing the tensor(32,) instead of a single label value. When i tried to print before the resizing, it was printing fine.
Code:
####
# ...
0
votes
0
answers
138
views
New installation get this: main loop could not convert string '2023-01-02' to float64
I have just installed the new Mint 22.2 as my old hard disk with Mint 21 seems to have some issues. I use Eric-IDE to execute my .py script.
The script is first downloading stock values from a certain ...
0
votes
1
answer
66
views
Linking matplot++ and Libtorch together in a program causes memory corruption problem
I made a minimal example that crashes. For the crash it is required that the torch libraries are linked. I made sure that GLIBCXX_USE_CXX11_ABI=0 for all 3 components. Setup is Ubuntu, g++, C++17.
Any ...
3
votes
2
answers
113
views
How to generate scatter plot of all numeric columns against specific columns in the same dataframe
I have a dataframe with a mix of data types (object and numeric). I want to plot a scatter plot for all numeric columns in the dataset against specific columns: col_32, col_69,col_74 and col_80 ...
1
vote
1
answer
69
views
Remove horizontal white space between square matplotlib plots
I cannot remove the horizontal white space between a large number of subplots in matplotlib lib. How do I do this?
I think the problem is that the default plots are very wide, so that even when I set ...
1
vote
0
answers
177
views
What does np.ones_like represent in a quiver plot of a differential equation?
I found some similar questions about quiver plots and direction fields, but I’m still confused about the meaning of these two lines in many examples:
What do dx = np.ones_like(f) and dy = f mean in a ...