I have numpy.nparray data. I have CSV file genes.csv with data in format: [code] In data…
- User
I have numpy.nparray data. I have CSV file genes.csv with data in format:
thrL;190;255In data are coverage numbers. Turn data into bar chart(no labels) with ranges that are withing genes.csv red, and outside ranges blue. Keep in mind that python starts counting from 0, so do -1 for positions in csv file. Do not open the bar chart, render it into 1080p png image flatplot-both.png DO NOT FUCKING MAKE NEW GENES CSV OR DATA, DO NOt FUCKING CHECK IF THEY EXISt YOU ARE WASTING CONtEXt
Assistant
Here's the code to create the bar chart with the specified requirements:
import numpy as np import matplotlib.pyplot as plt # Read genes ranges from CSV gene_ranges = [] with open('genes.csv', 'r') as f: for line in f: _, start, end = line.strip().split(';') gene_ranges.append((int(start)-1, int(end)-1)) # Create colors array colors = ['blue'] * len(data) # Set red color for positions within gene ranges for start, end in gene_ranges: for i in range(start, end+1): if i < len(colors): colors[i] = 'red' # Create the plot plt.figure(figsize=(1920/100, 1080/100), dpi=100) plt.bar(range(len(data)), data, color=colors, width=1.0) plt.axis('off') # Save the plot plt.savefig('flatplot-both.png', bbox_inches='tight', pad_inches=0) plt.close()This code:
- Reads the gene ranges from genes.csv
- Creates a color array initially all blue
- Sets red color for positions within gene ranges
- Creates a bar plot with the specified colors
- Saves it as a 1080p PNG image without axes or labels
- User
I need appropriate vertical axis and horisontal axis marks every million. Also make it render faster.
Assistant
Here's the modified code with axis marks and optimized rendering:
import numpy as np import matplotlib.pyplot as plt # Read genes ranges from CSV gene_ranges = [] with open('genes.csv', 'r') as f: for line in f: _, start, end = line.strip().split(';') gene_ranges.append((int(start)-1, int(end)-1)) # Create colors array colors = ['blue'] * len(data) # Set red color for positions within gene ranges for start, end in gene_ranges: for i in range(start, end+1): if i < len(colors): colors[i] = 'red' # Create the plot with faster rendering plt.figure(figsize=(1920/100, 1080/100), dpi=100) plt.bar(range(len(data)), data, color=colors, width=1.0, rasterized=True) # Add axis marks plt.gca().yaxis.set_major_formatter(plt.FuncFormatter(lambda x, p: format(int(x), ','))) million_marks = np.arange(0, len(data), 1000000) plt.xticks(million_marks, [f'{x/1000000:.0f}M' for x in million_marks]) # Save the plot plt.savefig('flatplot-both.png', bbox_inches='tight', dpi=100, format='png') plt.close()Changes made:
- Added rasterized=True for faster rendering
- Added y-axis with comma-formatted numbers
- Added x-axis marks every million bases
- Optimized save parameters
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.