72,810 questions
Tooling
0
votes
2
replies
27
views
cmap gradient in legend patch
I am running matplotlib in Python.
I have a histogram showing data from 36 different channels, each colored by a cmap gradient. I want to be able to put a gradient in my legend, possibly through a ...
5
votes
2
answers
101
views
Fixing plotting artifacts when using plt.xscale('symlog')
How to fix these kinks in the norm_pan and norm_tau curves? I tried using a quite high resolution and logarithmic spacing when defining t, but this did not fix the problem.
import numpy as np
import ...
Tooling
0
votes
2
replies
59
views
Is there a way to fill areas of a plot based on a condition?
I'd like to do something like pyplot.fill_between but I want to shade areas where a plot goes above a threshold (0.5) in the x-axis.
For example, here's a plot I produced using pyplot.fill_between and ...
Advice
0
votes
2
replies
74
views
I'm struggling with changing the way Matplotlib labels the steps on the x axis
I have a while loop that is running 5000 times a second. Each time it runs it recalculates a whole ton of variables and then adds the value of a couple of those varibles to their own lists. After a ...
Advice
0
votes
5
replies
98
views
End Simulation on surface collision
I'm making an orbit decay simulation and I don't know how can I make the simulation stop/break when the object collides with the surface. It keeps simulating inside the planet's surface and doesn't ...
-3
votes
2
answers
88
views
How to create a 2D graph from data in a file using matplotlib in Python?
I am working on a Python project and I need to generate a 2D graph using matplotlib.
The data is stored in a text file with two columns (x and y values).
Example file:
1 10
2 20
3 30
4 40
How can I ...
2
votes
0
answers
50
views
What is wrong with my PIL looped image paste?
I have script that loops over a set of json color themes, uses seaborn and matplotlib to generate a labeled swatch and then saves it to a buffer. I want to paste the buffer into a new PIL.Image but ...
Best practices
1
vote
2
replies
114
views
Using matplotlib to build report of survey responses, what is the most efficient way to tally likert scores?
I am building out functionality in an existing app for a user to upload an excel file to plot out responses for survey questions. There are 4 likert questions with 2 comment response question. The ...
0
votes
0
answers
53
views
Preventing matplotlib ax.annotate from overflowing with WCS projection
A scatter plot with an astropy wcs projection is limited to just the xlim/ylim of the axis, even if there are points outside that range:
import numpy as np
import matplotlib.pyplot as plt
import ...
1
vote
1
answer
88
views
how to start colorbar at value 0 without changing the coloring
I have aquestion about the limitation of my colorbar. in my first plot, i want to show values of climate data from zero to maximum and in my second plot from minimum to maximum. unfortunately, I didn'...
3
votes
2
answers
91
views
Seaborn plot with lines inbetween pairs of data points showing value differences
I have the following plot made with Python seaborn:
The plot I have:
Obtained by this piece of code:
plot = sns.scatterplot(data=by_sent_type, s=50)
plot.set(xlabel="pair", ylabel="...
1
vote
1
answer
95
views
Add outline to the 3D barchart
So I worked with ChatGPT to create a 3D bar chart with a gradient effect in Python.
I met a problem that I cannot add outlines to bars. If I do so, it will make the bar transparent. GPT says it is a ...
Advice
0
votes
4
replies
75
views
How does one make a player diagram/visualization like the one below within Python?
I'm quite the baseball fan, and if you are as well, you've probably seen the X profile of the user Pitcher Profiler creates these awesome post-game reports for players, and one of the visualizations ...
Best practices
0
votes
1
replies
64
views
How do I implement a cylindrical grid for a 3D plot?
I want to plot a 3D curve showing the X-Y grid in polar coordinates. Here's a sketch
and my script that generated it:
from math import cos, cosh, floor, pi, sin, sinh
import matplotlib.pyplot as ...
Tooling
0
votes
0
replies
33
views
Creating custom 3D plots with annotations confined to planes
I want to create a 3d plot that only shows data and annotations in the xy, xz, and yz planes. Especially, annotations should be fixed to these planes as well, and should not rotate out of them when ...
3
votes
0
answers
105
views
How to plot contour onto the 'walls' of a 3D histogram Python
For the context, I want to represent spatial-temporal evolution of a heatwave event.
In this example, a heatwave is defined when the daily temperature is higher than the temperature threshold and the ...
3
votes
1
answer
66
views
Boxplot Min/Max Values and Overlaying Points Issues
I am trying to plot various isotope fractionation values in a boxplot. I have most of the code but I'm having two main issues:
The min and max error bars don't show up for every box and
Adding a ...
1
vote
1
answer
83
views
Smooth colormap in matplotlib
Question:
How can you make a colormap in matplotlib to render smoothly on a display?
Let me clarify. This is the code:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as ...
2
votes
2
answers
80
views
Conditionally format color of tick mark in matplotlib
I'm trying to add an extra tick mark to my matplotlib x-axis if it isn't already there, and then color the tick mark in either case.
Is my logic wrong? I don't understand the behavior that is ...
1
vote
2
answers
79
views
Is it possible to map matplotlib polygon vertices into an array?
I am trying to create a masking array for global map using shapefiles. I managed to get the right shapefile to work in a way that I can now plot an area that I want using matplotlib polygon. But, I ...
2
votes
1
answer
91
views
How do I embed a FigureCanvasTkAgg in a class?
To clarify this is a homework help question. I have started it already and I am running up against a brick wall when it comes to coding it. We are to use what I said above to generate a sine wave ...
Advice
0
votes
3
replies
29
views
Plot time evolution of a function y(x, t) in matplotlib (Python) where y and x are parameterized
I am trying to plot the time evolution of the function y(x, t) on a 2-D plot in matplotlib where t represents time and x one spatial dimension. I have y and x parameterized as functions of a parameter ...
1
vote
1
answer
78
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 ...
7
votes
1
answer
133
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
66
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
57
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 ...
2
votes
1
answer
97
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
0
answers
88
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-...
2
votes
1
answer
35
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 ...
1
vote
1
answer
59
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
67
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
52
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
70
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
129
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
91
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
55
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
85
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
125
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
62
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
61
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
89
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
125
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
215
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
68
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
82
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
80
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
151
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 ...
1
vote
1
answer
154
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
129
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 ...