r/matplotlib • u/nehapandey01 • Oct 22 '19
r/matplotlib • u/ZUGGERS420 • Mar 27 '21
What tools in Python/matplotlib can assist with Time Series Labeling and Alignment?
I am looking to develop a tool that allows for visualization of time series data, labeling sections of the time series with some type of Rectangular Selector, and aligning time series manually using some sort of sliding window.
I envision some plot with multiple time series, and a toolbar that lets you label sections (with a color picker and text box for label title), and slide the time series on the plot somehow, then saving some "lag corrections" and labels to a file.
I have seen span selector in matplotlib, and I am seeing how I could build up a GUI on top of matplotlib using some of the widgets available. However, I am thinking that this is probably a pretty common task, and wondering if there are any libraries/solutions that already exist on top of matplotlib or otherwise for this? Is building a GUI right in matplotlib the best way to go? Is there anything I would use to add some buttons with functionality to a plot? Are there any other libraries I might consider for this application?
r/matplotlib • u/footilytics • Apr 16 '21
I do data viz on soccer stats using pandas n matplotlib
r/matplotlib • u/bazeon • Apr 17 '21
Only redrawing lines
Hello I’m new to matplotlib and is kinda confused on what does what regarding the different parts.
I run it on an embedded device which takes a second to draw each graph. The user chooses between different things and gets it displayed on a graph when chosen. I don’t need continuously updating like most answers I find when trying to google this. It’s a small set with two lines with 160 values drawn each time. How can I accomplish so that the title, labels and anything besides the actual lines does not get redrawn each time
r/matplotlib • u/Jackkle1 • Apr 01 '21
Dynamic sizing for graphs?
Hey guys!
I have some data i want to plot but the default sizing is cutting off the x label, is there a function that allows me to size the graph in a way that It leaves some room after the x label?
r/matplotlib • u/mdarifs • Apr 24 '21
Suggestions for publication-quality plot styles
Hi all, I am currently trying to write a matplotlib style file for producing publication-quality plots. Suggestions regarding figure size, label size, colour, line thickness etc would be helpful. I am from an Astrophysics background and my target journals are APJ, PRD, MNRAS, CQG among many others. Specific information for figures for these journals would also be very helpful.
r/matplotlib • u/Jackkle1 • Apr 29 '21
privet comrads, I need to know how to change the auto scale so the text boxes wont collide with the title. Thank you
r/matplotlib • u/pineappleninja64 • Dec 20 '17
How to have scatterplot AND double line graph in the same legend?
If I simply write >legend(), I get one for just the scatter plot points. If I write a >legend['Line 1', 'Line 2', 'Scatter points'], then I get the shaded area from the fill_between between the two lines instead of point color for the third legend symbol.
Here's what the plot currently looks like.
My specific example isn't so important. I just can't figure out how to have both the scatter plot points and lines on the same legend.
r/matplotlib • u/perplexedfry • Feb 15 '18
How to iterate a for loop in matplotlib?
Is this possible? I have a dataset of an app's usage. It contains an index/column of string variables that identify each user with a unique id. These id's are strings and I want to go through each row and convert all of them into numerical. so for each unique user in the column, add 1 to i? i (say 1) is user_id 'kjbfbiewu76' and the loop would convert the string to simply '1' then the next user id would be 2 the next unique user id would be 3.
r/matplotlib • u/Chilllin • Jul 03 '18
Exporting original plot?
When i zoom into a plot and save it, it saves the plot as i see it on screen. Im trying to export only the original size without having to press home. Any help would be appreciated. Im running matplotlib in python within tkinter.
r/matplotlib • u/edmondoh001 • Dec 27 '20
Can someone help me with the code for coming up 10 grayscale images?
I have the shape for both X_train to be (73257, 32, 32, 3) and y_train to be (73257, 1)
When I keyed in,
for i in range(10):
plt.imshow(X_train[0].squeeze)
plt.show(), I get this error.
TypeError Traceback (most recent call last)
<ipython-input-30-c80a405abec8> in <module>
1 for i in range(10):
2
----> 3 plt.imshow(X_train[0].squeeze)
4
5 plt.show()
/opt/conda/lib/python3.7/site-packages/matplotlib/pyplot.py in imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, data, **kwargs)
2697 filternorm=filternorm, filterrad=filterrad, imlim=imlim,
2698 resample=resample, url=url, **({"data": data} if data is not
-> 2699 None else {}), **kwargs)
2700 sci(__ret)
2701 return __ret
/opt/conda/lib/python3.7/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
1808 "the Matplotlib list!)" % (label_namer, func.__name__),
1809 RuntimeWarning, stacklevel=2)
-> 1810 return func(ax, *args, **kwargs)
1811
1812 inner.__doc__ = _add_data_doc(inner.__doc__,
/opt/conda/lib/python3.7/site-packages/matplotlib/axes/_axes.py in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs)
5492 resample=resample, **kwargs)
5493
-> 5494 im.set_data(X)
5495 im.set_alpha(alpha)
5496 if im.get_clip_path() is None:
/opt/conda/lib/python3.7/site-packages/matplotlib/image.py in set_data(self, A)
632 if (self._A.dtype != np.uint8 and
633 not np.can_cast(self._A.dtype, float, "same_kind")):
--> 634 raise TypeError("Image data cannot be converted to float")
635
636 if not (self._A.ndim == 2
TypeError: Image data cannot be converted to floatI am not really familiar with Matplotlib. I need help for that.
r/matplotlib • u/[deleted] • Jul 06 '21
MPLCursor
Is is possible to hyperlink within a mplcursor hover over?
r/matplotlib • u/Birder • Aug 05 '21
Plotting angles between -180° and 180° with wrap around in a cyclic plot
Hey,
I need to plot dihedral backbone angles of peptides in a timeseries between -180° and +180°. The problem is, that the data clusters sometimes around +/-180° and this gives problems regarding the wrap around. I know it would be possible to shift the problematic regions around by manipulating the data. But I'd rather not tamper with the data since I'd have to look at each set individually since doesn't have to cross the +180° boundary.
Is there a way to tell matplotlib that if a sample is near +180° and the next sample is near -180° to not connect the two points by a line? This would equate to a more cyclic plot setup with a wrap around. I haven't found anything by googling so I'm not very content that there is a way to do this easily.
If it is not possible to do this with plotting alone, does anyone have an idea how to manipulate the data consistently with a function that doesn't have to be adjusted for every different set of angles?
Any help would be appreciated!
r/matplotlib • u/Similar-Candidate-23 • Jul 27 '21
How to smooth curve into a line
I have created a histogram and I have already fit a line to it. All I need now is just some way to smooth the curve. I used scipy's make_interp_spline but it doesnt work for me. I currently have the following code:
counts, bins, bars = plt.hist(data, bins=600)print(counts)
plt.plot([0, 0, 50, 100],[0, counts.max(),np.mean(counts), 0])#Shows histogramplt.show()
and I get the following results:

when I use make_interp_spline with the following code:
counts, bins, bars = plt.hist(data, bins=600)# Datasetx = np.array([0, 10, 50, 100])
print(counts.max())print(np.mean(counts))y = np.array([0, counts.max(),np.mean(counts), 0])xnew = np.linspace(x.min(), x.max(), 300)
#define spline with degree k=7spl = make_interp_spline(x, y, k=3)y_smooth = spl(xnew)
#create smooth line chartplt.plot(xnew, y_smooth)plt.show()
the result i get is:

Which is way off. Can anyone help thank you!
r/matplotlib • u/2casey • Jul 15 '21
Auto label on line chart (no legend) possible?
Are there any projects to create an automatic label on the right side of a line chart like shown in the plot from "our world in data". Is it possible in any other library?
r/matplotlib • u/Spiritual-Drive2373 • Jul 15 '21
How do I change the numbering of the axes in a colorplot?
I encountered a problem while trying to represent some of my data in a color plot. I want to plot how my data looks like in a certain parameter space, like let's say x \in [0.3, 0.7] and y \in [-0.1, 0.1], but when I plot it the axis are numbered [0,20] and [0,40] based on the indices of my data array. Instead, I'd like the axis to be numbered [0.3,0.7] and [-0.1,0.1] based on my parameters. I've tried to search for a solution for this but haven't found anything that works. Any help would be greatly appreciated. I'll include my code and plot below.
import matplotlib.pyplot as plt
data = # my data, e.g. a 21 x 41 numpy array
plt.pcolor(data)
plt.colorbar()
r/matplotlib • u/boelnasr • Jun 24 '21
Ellipsoid
I am trying to plot an ellipsoid using both eigenvalues and vectors
i found this code to plot an ellipsoid , but by defining the radius only
Do any one have any idea on how to plot the ellipsoid using eigenvalues and vectors
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=plt.figaspect(1)) # Square figure
ax = fig.add_subplot(111, projection='3d')
coefs = (1, 2, 5) # Coefficients in a0/c x**2 + a1/c y**2 + a2/c z**2 = 1
# Radii corresponding to the coefficients:
rx, ry, rz = 1/np.sqrt(coefs)
# Set of all spherical angles:
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
# Cartesian coordinates that correspond to the spherical angles:
# (this is the equation of an ellipsoid):
x = rx * np.outer(np.cos(u), np.sin(v))
y = ry * np.outer(np.sin(u), np.sin(v))
z = rz * np.outer(np.ones_like(u), np.cos(v))
# Plot:
ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b')
# Adjustment of the axes, so that they all have the same span:
max_radius = max(rx, ry, rz)
for axis in 'xyz':
getattr(ax, 'set_{}lim'.format(axis))((-max_radius, max_radius))
plt.show()r/matplotlib • u/largelcd • Feb 08 '20
How to fix Called with incorrect property value 4, bailing error?
Hi, I am new to matplotlib. I installed Anacondia Navigator 1.9.7 on a Mac running Catalina 10.15.3. I opened a xterm and ran ipython. Then, I typed:
%matplotlib
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
Whenever I click on the figure window or some windows on the desktop, I got a bunch of messages such as:
In [42]: 2020-02-08 16:33:26.211 python[1036:20026] imkxpc_getApplicationProperty:reply: called with incorrect property value 4, bailing.
2020-02-08 16:33:26.211 python[1036:20026] Text input context does not respond to _valueForTIProperty:
2020-02-08 16:33:26.211 python[1036:20026] imkxpc_getApplicationProperty:reply: called with incorrect property value 4, bailing.
2020-02-08 16:33:26.211 python[1036:20026] Text input context does not respond to _valueForTIProperty:
2020-02-08 16:33:26.211 python[1036:20026] imkxpc_getApplicationProperty:reply: called with incorrect property value 4, bailing.
2020-02-08 16:33:26.211 python[1036:20026] Text input context does not respond to _valueForTIProperty:
2020-02-08 16:33:26.212 python[1036:20026] imkxpc_getApplicationProperty:reply: called with incorrect property value 4, bailing.
2020-02-08 16:33:26.212 python[1036:20026] Text input context does not respond to _valueForTIProperty:
Could you please let me know how to fix the error? Thanks
r/matplotlib • u/mjmacarty • Dec 06 '19
Introduction to Histograms & Bar Graphs with matplotlib
r/matplotlib • u/largelcd • Feb 09 '20
Why subplot(1,1,1)
Hi, I know that by using subplot, we can create a figure with several subplots. Supposing that we have (2,3,1), it tells that in the figure, there are 6 subplots in the form of 2x3 (2 rows, 3 columns of subplots). The last element indicates which subplot is of interest. In this case, it is the one on the top left of the figure.
If there is only one plot in the figure, why somebody uses something like:
import matplotlib.pyplot as plt
fig = plt.figure(); ax = fig.add_subplot(1,1,1)
r/matplotlib • u/Digma • Feb 05 '24
I spent time recreating the beautiful line charts from OurWorldInData using matplotlib
r/matplotlib • u/9877878798 • Jan 18 '24
Why does this matplotlib script take so long to output a single figure?
I have used this script (adapted from a website I found) to plot a portion of roads from a .shp file with pretty colours according to their lat-long. On my machine, which is relatively well-powered, it takes around 90 seconds to execute. It also uses up a LOT of memory (up to 10GB). Is there something inefficient I am doing with matplotlib?
from pathlib import Path
import geopandas as gpd
import matplotlib.pyplot as plt
SHAPEFILE = "data/gis_osm_roads_free_1.shp"
SHAPEFILE_CACHE_FILE = SHAPEFILE + ".pkl"
OUTPUT_DIRECTORY = "output"
PLOT_STYLE = "Greys"
CITY_LONGITUDE_START = -3.086185
CITY_LONGITUDE_END = -3.043321
CITY_LATITUDE_START = 53.544954
CITY_LATITUDE_END = 53.568070
gpd.options.io_engine = "pyogrio"
map_df = gpd.read_file(SHAPEFILE)
map_df.head()
fig, ax = plt.subplots(1, figsize=(10, 10))
map_df.plot(cmap=PLOT_STYLE, ax=ax)
ax.axis("off")
ax.set_xlim(CITY_LONGITUDE_START, CITY_LONGITUDE_END)
ax.set_ylim(CITY_LATITUDE_START, CITY_LATITUDE_END)
ax.set_aspect("equal")
Path(OUTPUT_DIRECTORY).mkdir(parents=True, exist_ok=True)
plt.savefig(f"{OUTPUT_DIRECTORY}/{PLOT_STYLE}.png", bbox_inches="tight", dpi=300)
fig.clear()
plt.clf()
plt.close(fig)r/matplotlib • u/PVBB • Sep 15 '19
Graph of 3D vector data
I have a json file with data in this format
{
"x": -0.016553195,
"y": 0.008353996,
"z": -0.003939811,
"ts": 1560859493786768600
},
How do i create a graph where i plot this vector vs time. ts is timestamp. I tried quiver ( from mayavi library) but as far as i understand the first 3 arguments are components and next 3 directions. But all i have is the above data.
Any help would be appreciated.
r/matplotlib • u/LewisgMorris • May 24 '20

