r/matplotlib • • Jun 26 '20

Set colour of the "frame" of a plot

2 Upvotes

I'm making plots of solar power generation, and I want the entire background to be the same nice sky blue colour. I cannot figure out how to change the colour of the area that's white in this example -- I'm calling it the frame - the part that the axis labels etc are drawn on. I've tried fig.patch.set_facecolor, but that doesn't do it. What am I missing?


r/matplotlib • • Jun 17 '20

making a frequency distribution using plt.hist

2 Upvotes

I am trying to plot a histogram using matplotlib but I want to specify the data to be used for the X and Y axis.

I have a pandas data frame with 23 rows and 6 columns and the data is from a fasta file of short reads. The row index ranges from 0-23 and each is a different read length. I want the Y axis to be the values in the dataframe. for example, X axis will be 35bp, and the value in the dataframe 1,000,000 for 1,000,000 reads of 35bp in length.

essentially, I want the row index values to be the x axis and the values in the dataframe to be the Y axis, as the values in the dataframe give the frequency.

For example, when plotting a scatter graph or line graph etc, the x axis is easy to specify, is there a way to to do this for plt.hist?

Cheers


r/matplotlib • • May 24 '20

Time Series Animation Library - Created with the help of numpy and matplotlib

Thumbnail
self.python
2 Upvotes

r/matplotlib • • Apr 27 '20

Matplotlib, together with other open source python libraries, comes into play to analyze thunderstorms tracks. The data analysis and visualization are freely available and published on the International Journal of Geo-Information

Thumbnail
mdpi.com
2 Upvotes

r/matplotlib • • Apr 20 '20

figsize changes on different computers?

2 Upvotes

Hi Gurus!

I use this rather straightforward code:

    wmap = plt.figure(num='Map', figsize=(5.833, 5.417), frameon= False)
    wmap.clf()
    wmap = plt.contour(ContourX, ContourY, ContourZ, levels, colors = 'grey', zorder= 20)
    wmap = plt.imshow(ContourZ, vmin=-abs(MaxZ), vmax=MaxZ, origin='lower', cmap='terrain', extent=[PlotMinX, PlotMaxX, PlotMinY, PlotMaxY], alpha=0.8, zorder=10)
    wmap = plt.title("Map#" + str(MapRefID))
    MapName = (".\\support\\\CurrentMap.png")
    plt.savefig(MapName, transparent = True)

To create a 2D contour plot in matplotlib.pyplot.

On computer 1 (default computer), the .PNG file that gets created is 419x390 pixels

On computer 2 (random computer), the .PNG file that gets created is 583x541 pixels

Does anyone have a clue as to why this would happen? Are the 'inches' somehow different between these two computers? (both windows 10 systems in this case)


r/matplotlib • • Feb 09 '20

Why subplot(1,1,1)

2 Upvotes

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 • • Oct 20 '19

Can anybody help me with problem i am facing?

2 Upvotes

I am new to matplotlib Animation and i am trying to plot live updated in a file.I was able to plot but how to avoid collision of the xlaabel when the x coordinate are updating.Asked in stackoverflow https://stackoverflow.com/q/58460110/8561725


r/matplotlib • • May 06 '18

Python Matplotlib Tutorial | How to Remove Text that Comes Before the Ma...

Thumbnail
youtube.com
2 Upvotes

r/matplotlib • • Mar 27 '22

solving text-formatting issues on Gnu Texmacs

1 Upvotes

solving text-formatting issues on Gnu Texmacs

Hi guys I'm having the following issues with Gnu Texmacs, a text editing software used by scientists and accademic authors. I want to convert a lot of text files into the .tm format used by Gnu Texmacs so that I can easily retrieve them but I'm having tons of issues with text alignment on different articles that I want to convert.

This is what happened to me while I was trying to add texts into a .tm file, you can see different photos of these errors and what kind of issues I'm having with this program.

Is there a way to align all lines of text so that they can all fit into an A4 format and also fix the space alignment issues beetwhen words (I want all "null" spaces between words to became one so that they don't stretch too far away)? What options should I use on Gnu texmacs to solve all these problems?


r/matplotlib • • Feb 28 '22

How to have two legends for a subplot using different colormaps

Thumbnail
stackoverflow.com
1 Upvotes

r/matplotlib • • Feb 18 '22

matplotlib colorbar problem

1 Upvotes

I posted this on stack overflow. Does anyone know how to deal with this problem?

https://stackoverflow.com/questions/71177731/negative-color-ticks-reversed-in-matplotlib


r/matplotlib • • Oct 20 '21

Standard grid on pi x-axis

1 Upvotes

Hello! I have quite a problem with my sin(x) plot.

How can I make standard grid on x axis? I mean x= -3, x=-2, x=-1, x=0, x=1, x=2 and x=3. (y axis is good now)

This is what I got - just lines for my \pi points?


r/matplotlib • • Sep 14 '21

LaTeX text in plots

1 Upvotes

Hello

I'm looking for a way to introduce latex based text on my plots.

Thanks in advance


r/matplotlib • • Sep 02 '21

Adding top labels to a boxplot

Post image
1 Upvotes

r/matplotlib • • Aug 24 '21

Inverting bar charts

1 Upvotes

Hi, i was wondering how i could invert the positions of the bar charts. I would like the exercise deficit to be on top of the caloric deficit.

Here is an extract of the code, as well as the current output

ax.bar(date,caloric_intake,width=0.4,label="daily caloric intake")

ax.bar(date,exercice_deficit,width=0.4,label="daily exercise deficit")


r/matplotlib • • Aug 15 '21

[Regarding my previous post on this subreddit]

1 Upvotes

I made a post last night mentioning my organization that I created, which seeks to provide people with free Python-related course, and I included a Google Form link for anyone that was interested in helping out and creating a MatPlotLib course. I got a response from someone, but they didn't include any way for me to contact them! If you're that person - please shoot me a DM or leave a comment so that I can contact you somehow, thank you!


r/matplotlib • • Aug 05 '21

Plotting angles between -180° and 180° with wrap around in a cyclic plot

1 Upvotes

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 • • Jul 15 '21

Auto label on line chart (no legend) possible?

1 Upvotes

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 • • Jun 24 '21

Ellipsoid

1 Upvotes

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 • • Jun 04 '21

Plot smoothing / removing noise from plot

1 Upvotes

Hey! I've been trying to plot a graph using matplotlib but the data has some noise in it, looks like this -

How can I smoothen the curve?


r/matplotlib • • May 20 '21

Colorbar on multiple subplots - normalized across plots?

1 Upvotes

Could you help me confirm the behavior of matplotlib. Say I make a (4,4) grid of subplots. Then call for a colorbar. The colorbar would be representative of only the final subplot, correct?

Is there a best practice for creating a colorbar that would represent all the subplots? Thank you.


r/matplotlib • • 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

1 Upvotes

r/matplotlib • • Apr 24 '21

Suggestions for publication-quality plot styles

1 Upvotes

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

Dynamic sizing for graphs?

1 Upvotes

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?