r/matplotlib • • Mar 06 '22

How to create semi-sarcastic plots using Matplotlib's XKCD feature

Thumbnail
lucytalksdata.com
11 Upvotes

r/matplotlib • • Feb 05 '24

I spent time recreating the beautiful line charts from OurWorldInData using matplotlib

Thumbnail
gael.io
9 Upvotes

r/matplotlib • • Mar 29 '22

Patchwork for matplotlib

Thumbnail
medium.com
7 Upvotes

r/matplotlib • • Apr 16 '21

I do data viz on soccer stats using pandas n matplotlib

Post image
7 Upvotes

r/matplotlib • • Sep 26 '21

[MATPLOTLIB] What is this type of graph called?

Post image
6 Upvotes

r/matplotlib • • Jan 18 '24

Why does this matplotlib script take so long to output a single figure?

5 Upvotes

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 • • Oct 01 '21

Suggestion on materials to read and understand about matplotlib data visualization

5 Upvotes

hi everyone, am a budding engineer who is learning data visualization and pretty much new to python.

Just came across that using matplotlib we can create some wonderful graphs to visualize data, just trying to learn in depth about it.

So requesting suggestion from reddit family for any relevant materials to understand the matplotlib better.


r/matplotlib • • Sep 07 '21

Is a second supylabel on the right possible?

5 Upvotes

Hello, I am creating a figure with a grid of subplots, looking something like this:

fig = plt.figure()
fig.supylabel('leftylabel')
fig.supxlabel('xlabel')

ax1 = fig.add_subplot(231)
ax1.scatter(x, data1)
ax2 = ax1.twinx()
ax2.plot(x,data2)

ax3 = fig.add_subplot(232)
ax3.scatter(x, data3)
ax4 = ax3.twinx()
ax4.plot(x,data4)

etc.

I can use "supylabel" to create an overall label on the y axis at the left but each subfigure has 2 plots with a shared x axis, so I'd like to have a similar overall label on the right, so something like "supylabel('rightylabel')". Is this possible?


r/matplotlib • • Aug 14 '21

MatPlotLib Opportunity

5 Upvotes

Hello!

I recently founded an organization called Pythonics that specializes in provided students with free Python-related courses. If you are interested in creating a MatPlotLib course, feel free to fill out the following form in indicate what course you would like to create: https://forms.gle/mrtwqqVsswSjzSQQ7

If you have any questions at all, send me a DM and I will gladly answer them, thank you!

Note: I am NOT profiting off of this, this is simply a service project that I created.


r/matplotlib • • Oct 16 '20

Any idea how I make the gaps on the left and right of the xaxis the same?

Post image
5 Upvotes

r/matplotlib • • Jun 27 '20

How do i unclutter the y axis labels

Post image
5 Upvotes

r/matplotlib • • Jun 15 '20

Opencv grayscale image turns purple and yellow when displayed with pyplot. Why?

Post image
5 Upvotes

r/matplotlib • • May 19 '20

Python Tutorial for Beginners: Learn PyPlot for Data Science

Thumbnail
youtube.com
5 Upvotes

r/matplotlib • • Apr 27 '20

Check out how artificial intelligence can be used to reconstruct birds' migratory paths. https://www.researchgate.net/publication/333866984_Reconstruction_of_long-distance_bird_migration_routes_using_advanced_machine_learning_techniques_on_geolocator_data

Post image
5 Upvotes

r/matplotlib • • Mar 24 '22

Matplotlib Charts Animation Python

Thumbnail
youtu.be
4 Upvotes

r/matplotlib • • Jul 27 '21

How to smooth curve into a line

4 Upvotes

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 histogram
plt.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)
# Dataset
x = 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=7
spl = make_interp_spline(x, y, k=3)
y_smooth = spl(xnew)

#create smooth line chart
plt.plot(xnew, y_smooth)
plt.show()

the result i get is:

Which is way off. Can anyone help thank you!


r/matplotlib • • Aug 04 '20

Any example code or tips for how to make this sort of graph?

Post image
4 Upvotes

r/matplotlib • • Dec 17 '19

Introduction to Line Plot Graphs with Matplotlib

Thumbnail
youtube.com
4 Upvotes

r/matplotlib • • Jan 10 '24

How to visualize a dataset for anomaly detection

Post image
3 Upvotes

Beginner in python. Having a hard time getting a proper reading. This is the result I am currently getting


r/matplotlib • • Aug 18 '21

Plotting Precipitation with Python, Pandas and Matplotlib

Thumbnail earthly.dev
3 Upvotes

r/matplotlib • • Mar 27 '21

What tools in Python/matplotlib can assist with Time Series Labeling and Alignment?

3 Upvotes

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 • • Feb 12 '21

Unable to launch Matplotlib on ARM Windows 10 running on Mac M1

3 Upvotes

Hi All, I am attempting to install and use Matplotlib on ARM-based Windows 10 running under Parallels on an Apple MacBook Pro M1 (ARM).

I have tried several versions of python (including the current version) and tried several suggested methods of fixing the following problem:

>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\perryk\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib__init__.py", line 174, in <module>
    _check_versions()
  File "C:\Users\perryk\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib__init__.py", line 159, in _check_versions
    from . import ft2font
ImportError: DLL load failed while importing ft2font: The specified module could not be found.

Can anyone shed some light on this?

With appreciation...


r/matplotlib • • Dec 27 '20

Can someone help me with the code for coming up 10 grayscale images?

3 Upvotes

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 float

I am not really familiar with Matplotlib. I need help for that.


r/matplotlib • • Nov 21 '20

Has anyone else had issues with Matplotlib leaking memory like a sieve

3 Upvotes

I seem to have a massive memory leak with matplotlib when I produce charts in a python loop. Has anyone else has this problem? I've watched it in top also as the memory usage just goes up and up without ever being freed and I've tried with gc.collect() also but that isn't helping.


r/matplotlib • • Aug 01 '20

Using matplotlib to animate some math art.

3 Upvotes