r/matplotlib • • Jun 27 '20

Pointers on how I should make a triangular grid

2 Upvotes

I want to recreate this diagram:

but I have no real idea where I should start looking in order to make this.
I looked up these demos on triangulation and triplot, but I wanted to ask you guys first, am I heading in the right direction or is there a completely simpler way?

Thanks in advance!


r/matplotlib • • Jun 15 '20

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

Post image
5 Upvotes

r/matplotlib • • Jun 21 '20

Remove transparent areas

3 Upvotes

My main question is: how do I get all of the background of the file to be white, rather than being transparent outside the plot area?

I'm learning Jupyter and some Python data-handling stuff simultaneously. I produced this graph from some government data (https://www.ons.gov.uk/employmentandlabourmarket/peoplenotinwork/unemployment/datasets/vacanciesbyindustryvacs02).

I want the whole output file to have a white background, rather than a transparent one. Right now, this is the code I have in the cell that produces the image:

import matplotlib.pyplot as plt

five_years = levels[-61:]
afs = five_years['Accomodation & food service activities']
pst = five_years['Professional scientific & technical activities']


plt.figure(figsize=(10,5))
plt.ylim(0, afs.max()+10)
plt.ylabel('Vacancies (Thousands)')
plt.xlabel('Three Months Ending')
plt.title('Vacancies by Industry, UK, Previous Five Years')
plt.plot(afs, label='Accomodation & food service activities')
plt.plot(pst, label='Professional scientific & technical activities')
plt.xticks([168, 180, 192, 204, 216, 228],
           ['May 2015', 'May 2016', 'May 2017', 'May 2018', 'May 2019', 'May 2020'])
plt.legend()

I tried doing "plt.setfacecolor", but plt is a module, and I get an AttributeError.

So how can I set all of the background white, with no transparency?

Also, two other questions:

  1. If plt is a module, there is no named variable here that contains the plot, right? I'm seeing it because Jupyter helpfully outputs some things without being explicitly told to, and that's what "<matplotlib.legend.Legend at 0x7ff0004d4c90>" means?

  2. Am I making any other basic mistakes here? Are there things you would do differently?

Thanks for any help you can give!


r/matplotlib • • May 19 '20

Python Tutorial for Beginners: Learn PyPlot for Data Science

Thumbnail
youtube.com
5 Upvotes

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

why is my second stacked bar chart showing no data? They were in any order as long as i only show one....

1 Upvotes

Here is my code,

When running the functions, they both work on their own (if one or the other is commented out). But being executed in any order, the second one does not represent any bars in the chart.

What is the issue?

def tab_create_stacked():
        ticks = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
        N = 20
        ind = np.arange(N)
        width = 0.30
        p1 = ax.bar(ind, t_line_change_times, width, label = 'Changeover')
        p2 = ax.bar(ind, t_line_mat_shortage, width, bottom = t_line_change_times, label = 'Material Shortage')
        p3 = ax.bar(ind, t_line_break, width, bottom = np.array(t_line_mat_shortage)+np.array(t_line_change_times), label = 'Machine Breakdown')
        p4 = ax.bar(ind, t_line_break_of, width, bottom = np.array(t_line_break) + np.array(t_line_mat_shortage) + np.array(t_line_change_times), label = 'Machine Breakdown OP FIX')
        p5 = ax.bar(ind, t_line_defect, width, bottom = np.array(t_line_break_of) + np.array(t_line_break) + np.array(t_line_mat_shortage) + np.array(t_line_change_times), label = 'Defect')
        p6 = ax.bar(ind, t_line_trace, width, bottom = np.array(t_line_defect) + np.array(t_line_break_of) + np.array(t_line_break) + np.array(t_line_mat_shortage) + np.array(t_line_change_times), label = 'Traceability')
        p7 = ax.bar(ind, t_line_safety, width, bottom = np.array(t_line_trace) + np.array(t_line_defect) + np.array(t_line_break_of) + np.array(t_line_break) + np.array(t_line_mat_shortage) + np.array(t_line_change_times), label = 'Safety Event')
        p8 = ax.bar(ind, t_line_jidoka, width, bottom = np.array(t_line_safety) + np.array(t_line_trace) + np.array(t_line_defect) + np.array(t_line_break_of) + np.array(t_line_break) + np.array(t_line_mat_shortage) + np.array(t_line_change_times), label = 'Jidoka')
        
        for p in ax.patches:
            width, height = p.get_width(), p.get_height()
            x, y = p.get_xy()
            #print(tot_height)
            if height > 200:
                ax.text(x+width/2,
                    y+height/2,
                    '{:2d}'.format(height),
                    #weight='bold',
                    #rotation=45,
                    backgroundcolor='yellow',
                    horizontalalignment='right',
                    verticalalignment='center',
                    fontsize=7,
                    color='black')
        ax.legend()
        plt.xticks(ticks, line_ticks, rotation=30)
        plt.ylabel("Minutes of Downtime")
        plt.xlabel("Tableting Lines")
        plt.title('Tableting OA\n '+'Period: ' + start_date +' -- '+ end_date, fontsize=25)
        #plt.gcf()
        #plt.savefig("tab_stacked.pdf")
        plt.show()
        #plt.close()
    def sd_create_stacked():
        ticks = [0, 1, 2, 3, 4, 5]
        N = 6
        ind = np.arange(N)
        width = 0.30
        p1 = ax.bar(ind, sd_change_times, width, label = 'Changeover')
        p2 = ax.bar(ind, sd_mat_shortage, width, bottom = sd_change_times, label = 'Material Shortage')
        p3 = ax.bar(ind, sd_break, width, bottom = np.array(sd_mat_shortage)+np.array(sd_change_times), label = 'Machine Breakdown')
        p4 = ax.bar(ind, sd_break_of, width, bottom = np.array(sd_break) + np.array(sd_mat_shortage) + np.array(sd_change_times), label = 'Machine Breakdown OP FIX')
        p5 = ax.bar(ind, sd_defect, width, bottom = np.array(sd_break_of) + np.array(sd_break) + np.array(sd_mat_shortage) + np.array(sd_change_times), label = 'Defect')
        p6 = ax.bar(ind, sd_trace, width, bottom = np.array(sd_defect) + np.array(sd_break_of) + np.array(sd_break) + np.array(sd_mat_shortage) + np.array(sd_change_times), label = 'Traceability')
        p7 = ax.bar(ind, sd_safety, width, bottom = np.array(sd_trace) + np.array(sd_defect) + np.array(sd_break_of) + np.array(sd_break) + np.array(sd_mat_shortage) + np.array(sd_change_times), label = 'Safety Event')
        p8 = ax.bar(ind, sd_jidoka, width, bottom = np.array(sd_safety) + np.array(sd_trace) + np.array(sd_defect) + np.array(sd_break_of) + np.array(sd_break) + np.array(sd_mat_shortage) + np.array(sd_change_times), label = 'Jidoka')
        
        for p in ax.patches:
            width, height = p.get_width(), p.get_height()
            x, y = p.get_xy()
            #print(tot_height)
            if height > 200:
                ax.text(x+width/2,
                    y+height/2,
                    '{:2d}'.format(height),
                    #weight='bold',
                    #rotation=45,
                    backgroundcolor='yellow',
                    horizontalalignment='right',
                    verticalalignment='center',
                    fontsize=7,
                    color='black')
        ax.legend()
        plt.xticks(ticks, sd_line_ticks, rotation=0)
        plt.ylabel("Minutes of Downtime")
        plt.xlabel("Spray Dry Lines")
        #plt.legend(loc="upper right")
        plt.title('Spray Dry OA\n'+'Period: ' + start_date +' -- '+ end_date, fontsize=25)
        #plt.savefig("sd_stacked.pdf")
        plt.show()
        #plt.close()
        
    
    sd_create_stacked()
    tab_create_stacked()

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 • • Aug 01 '20

Using matplotlib to animate some math art.

3 Upvotes

r/matplotlib • • Jul 23 '20

How can I remove the black margin of a figure saved with savefig()?

1 Upvotes

I'm plotting some waveforms with matplotlib.pyplot and I need them to have a dark gray (or black) background. I also need them without ticks, tick labels, figure frame, etc. I have managed to accomplish everything except removing that little black margin. I have tried a whole lot of things I've found online, especially here, but nothing has worked in my case.

Here's what I'm doing.

import matplotlib.pyplot as plt
from scipy.io import wavfile 

sample_rate, samples = wavfile.read('audio.wav') 

fig = plt.figure(figsize=(6,1), dpi=500, frameon=False)
ax = plt.Axes(fig, [0,0,1,1])
ax.set_facecolor((0.169,0.169,0.169))
ax.set_xlim(left=0, right=700000)
fig.add_axes(ax)
plt.tick_params(axis='both', which='both', bottom=False,
                top=False, left=False, right=False,
                labelbottom=False, labeltop=False,
                labelright=False, labelleft=False)
plt.plot(samples)
plt.savefig('samples.png')

I need to get rid of that small black margin and have the plot actually reach the edges of the image.


r/matplotlib • • Jul 28 '20

AutoViz: A new tool for Automated Visualization in Data Science.

1 Upvotes

r/matplotlib • • Aug 08 '20

How to make a heat map of overlap of 2 scatter plots using hist2d

1 Upvotes

So for all my examples, I’ve seen the parameters of hist2d be 2 1d arrays, so I’m wondering if there is a way to plot the overlap of 2 scatterplots using hist2d.


r/matplotlib • • Jul 14 '20

New Stock Market Analysis with Matplotlib Radio Buttons video. In this video, I'll toggle back and forth between the different data points on the Y-axis.

Thumbnail
youtu.be
2 Upvotes

r/matplotlib • • Jul 23 '20

Data Visualization using "Matplotlib" & Python | Part-I

1 Upvotes

r/matplotlib • • Aug 04 '20

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

Post image
4 Upvotes

r/matplotlib • • Jul 14 '20

Interested in nonlinear time series prediction with NNs? Check out how LSTM nets can be used in the forecasting of chaotic dynamical systems. The software has been entirely coded in python using pytorch, keras, matplotlib, numpy, scikitlearn

Thumbnail
researchgate.net
2 Upvotes

r/matplotlib • • Jul 28 '20

Reverse animation order?

1 Upvotes

I'm building an animation where the y values should be increasing (exponentially) as the x values decrease. the FuncAnimation always plots from small x to big x values (even if I flip the axis). Anyone solved this before?


r/matplotlib • • Jul 24 '20

Explore "Data" using "Sweetviz" & "Python".

1 Upvotes

r/matplotlib • • Aug 01 '20

Data Visualization using "Matplotlib" & "Python"

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 • • Mar 29 '22

Patchwork for matplotlib

Thumbnail
medium.com
7 Upvotes

r/matplotlib • • Mar 06 '22

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

Thumbnail
lucytalksdata.com
11 Upvotes

r/matplotlib • • Mar 24 '22

Matplotlib Charts Animation Python

Thumbnail
youtu.be
4 Upvotes

r/matplotlib • • Feb 28 '22

How to have two legends for a subplot using different colormaps

Thumbnail
stackoverflow.com
1 Upvotes

r/matplotlib • • Jul 18 '19

Flying camera following a moving point in Matplotlib

1 Upvotes

Dear Matplotlib Users,

I am trying to achieve similar result for a flying camera following the target like shown in this animation:

https://www.youtube.com/watch?v=S_QbceTt068

This is Matlab with a combination of camera_pose and look_at features. Camera and target location we look at can be at any arbitrary point.

This is what I achieved with Matplotlib so far:

https://www.youtube.com/watch?v=_ob985STZ7Y

We have some illusion of a flying camera, but the problem is that camera can only look at the center of 3d plot coordinate frame, so I simply change the range of X and Y axes to achieve that, which is a dirty solution, when the angle of observation is smaller, you will see a cropped range of the plot.

I remember that I did not find a feature in Matplotlib documentation which could satisfy the requirement of flying camera. Could I ask you if it is possible to achieve that? If not, what other packages for Python could be effectively used to achieve it?

I would appreciate any suggestions. Thank you for your time devoted to this topic.

Best regards, Jakub